如何将无状态功能组件转换为有状态组件,以便像无状态组件一样使用生命周期方法并将 Prop 传递给它。
( export default JobCard = (props) => {
............
}
)
我需要将其转换为有状态组件,以便使用生命周期方法并将 Prop 传递给返回函数,就像这里传递 Prop 的方式一样。提前谢谢你。
最佳答案
你可以这样做:
export default class JobCard extends React.Component {
render() {
// here you can access props passing down from
// parent components like: this.props
return (
<div>
Hi, I'm a super smart component!
</div>
);
}
}
关于javascript - Stateful 和 Functional 无状态组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49912494/