Stateful 和 Functional 无状态组件

Stateful and Functional stateless components

如何将无状态功能组件转换为有状态组件,以便像无状态组件一样使用生命周期方法并向其传递道具。

( export default JobCard = (props) => { 
   ............
 }
)

我需要将其转换为有状态组件,以便使用生命周期方法并将 props 传递给 return 函数,就像此处传递 props 的方式一样。提前谢谢你。

你可以这样做:

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>
    );
  }
}