關於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