javascript - Stateful 和 Functional 无状态组件

标签 javascript reactjs react-native state stateless

如何将无状态功能组件转换为有状态组件,以便像无状态组件一样使用生命周期方法并将 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/

相关文章:

javascript - 无法从实时数据库 firebase 迭代子项?

javascript - 为什么 Closure 在使用 function.apply 时不对参数进行类型检查?

reactjs - 如何使 Material UI 图标表现得像 anchor 标签?

javascript - 在 React 中从 child 调用函数

javascript - React Native 组件未使用 componentWillMount 或 componentDidMount 中的异步 redux 操作进行渲染

firebase - 从 firebase 渲染 FlatList 中的数据

javascript - 数据表排序不按降序显示

javascript - 如何在 DataTables 按钮中设置 href?

javascript - 以 HTML 格式打印 Python 输出

reactjs - 使用 React 路由器定义传递额外参数