我如何理解 React.Component 和高阶组件之间的区别?
How can I understand differences between React.Component and Higher-Order Components?
我已经习惯了这种代码风格。
import React from 'react';
class App extends React.Component {
render() {
return (
<>This is my app</>
);
}
}
但是现在,我看到所有的东西都是高阶组件。
import React from 'react';
function App() {
return (
<>This is my app</>
);
}
我还不了解他们。有时,我读了一个用 class 风格写的例子,但无法将想法转化为高阶组件。请给我解释一下或者给我一些相关的关键字、帖子或其他类型的文档?
谢谢!
我想我解决了我的问题。
首先是Class和Function Component的区别,不是Higher-Order Component
其次,要将Class组件转换为Function组件,我必须了解如何为它们添加状态和生命周期方法。
https://reactjs.org/docs/state-and-lifecycle.html
https://itnext.io/add-state-and-lifecycle-methods-to-function-components-with-react-hooks-8e2bdc44d43d
感谢您提出一些有用的意见!
问题已关闭。
我已经习惯了这种代码风格。
import React from 'react';
class App extends React.Component {
render() {
return (
<>This is my app</>
);
}
}
但是现在,我看到所有的东西都是高阶组件。
import React from 'react';
function App() {
return (
<>This is my app</>
);
}
我还不了解他们。有时,我读了一个用 class 风格写的例子,但无法将想法转化为高阶组件。请给我解释一下或者给我一些相关的关键字、帖子或其他类型的文档?
谢谢!
我想我解决了我的问题。
首先是Class和Function Component的区别,不是Higher-Order Component
其次,要将Class组件转换为Function组件,我必须了解如何为它们添加状态和生命周期方法。
https://reactjs.org/docs/state-and-lifecycle.html
https://itnext.io/add-state-and-lifecycle-methods-to-function-components-with-react-hooks-8e2bdc44d43d
感谢您提出一些有用的意见!
问题已关闭。