zoukankan      html  css  js  c++  java
  • 关于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>
          }
        }
  • 相关阅读:
    第三次作业
    第二次作业
    第一次作业
    第五次作业
    第四次作业
    第三次作业
    第二次作业
    随笔
    第五次作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/nyhhd/p/12496194.html
Copyright © 2011-2022 走看看