关于react 父级组件更新数据触发子组件更新渲染问题


1.直接在子组件中使用(不推荐)

  class child extends component{

    render(

      <div>{this.props.value}</div>

    )

  }

 

2.自己在构造函数中初始化一个值,在将 status 通过 componentWillReceiveProps 生命周期方法 更新(转换为子组件的state)

  class Child extends Component { constructor(props) { super(props); this.state = { someThings: props.someThings }; } componentWillReceiveProps(nextProps) { this.setState({someThings: nextProps.someThings}); } render() { return <div>{this.state.someThings}</div> } }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM