React Hooks 常量组件与功能组件 [英] React Hooks Const Component vs Functional Component
问题描述
我有一个在谷歌上搜索后无法弄清楚的问题,我认为最好在这里问.我了解功能组件和类组件之间的区别,但是 const 组件和功能组件之间有什么区别?
I have a question I couldn't figure out after googling, I thought it would be better to ask here. I understand the difference between a functional component and a class component, but what's the difference between const component to a functional component?
例如
const Home = () => {
return (
<div>Home</div>
)
}
到
function Home() {
return (
<div>Home</div>
)
}
两者都可以使用钩子,那么主要区别是什么?
Both of them can use hooks, so what's the main difference?
推荐答案
没有有效的区别.首先是使用箭头函数表达式创建一个函数语法并将其存储为常量,第二个是创建一个普通函数.
There is no effective difference. First is creating a function using Arrow function expressions syntax and storing it to a constant and the second is creating a plain function.
两者都是执行完全相同任务的函数,返回组件 JSX 代码进行渲染.
Both are functions that will perform the exact same task, return the component JSX code for rendering.
此外,没有这样的术语或概念Const Component";有功能组件"和类组件".
Also, there is no such term nor concept "Const Component"; there are "Functional Components" and "Class Components".
这篇关于React Hooks 常量组件与功能组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!