Javascript 有状态和功能无状态组件

Javascript 有状态和功能无状态组件,javascript,reactjs,react-native,state,stateless,Javascript,Reactjs,React Native,State,Stateless,如何将无状态功能组件转换为有状态组件,以便使用生命周期方法并像无状态组件一样向其传递道具 ( export default JobCard = (props) => { ............ } ) 我需要将其转换为有状态组件,以便使用生命周期方法并将props传递给返回函数,就像这里传递props一样。提前谢谢。您可以这样做: export default class JobCard extends React.Component { render() {

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

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

我需要将其转换为有状态组件,以便使用生命周期方法并将props传递给返回函数,就像这里传递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>
    );
  }
}
导出默认类JobCard.Component{
render(){
//在这里,您可以访问从
//父组件,如:this.props
返回(
嗨,我是一个超级智能组件!
);
}
}

谢谢。比如让道具=this.props?@PremKumar有关道具如何在react Native中工作的更多信息,请参阅是的,您可以这样做。在无状态组件中,您可以访问像
props.name
这样的道具;在有状态组件中,您可以像
this.props.name
@konekoya一样访问道具。谢谢