[英]Why doesn't create-react-app use an arrow function component?
现在(从今年年初开始)当您使用 Create React App 引导 React 应用程序时,它现在会生成 function 组件而不是 class 组件:
function App() {
// ...
}
我想知道为什么他们不使用箭头 function 组件,因为 ES6 箭头函数已经出现了一段时间,而且你不必绑定this
:
const App() => {
// ...
};
使用箭头 function 组件是否有任何明显的缺点,而不是可能导致他们做出该决定,或者仅仅是该语法更熟悉?
他们使用常规函数来使其与 react 文档保持一致。
来源: https://github.com/facebook/create-react-app/pull/6655
另外你不必绑定这个
这里并不是真正的好处,因为this
不会在功能组件中使用。
As I know, in the next versions there will be a performance difference between class and function components, so that's why they are changing to function, about arrow function, I like it more than regular functions as you said there are no need to bind in它,但有一些东西你不应该在其中使用箭头,你可以从这里阅读它们。 所以这可能是因为这些原因。希望它有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.