vevlins

react16 的新生命周期下是推荐把所有的 props 并入到 state 吗?

  •  
  •   vevlins · Jul 18, 2018 · 2058 views
    This topic created in 2860 days ago, the information mentioned may be changed or developed.

    getDerivedStateFromProps的意义是如此吧?大家实践当中都是怎么做的,会把 props 放到 state 里面统一管理状态还是依然通过const {xxx} = this.props的方式拿数据?

    1 replies    2018-08-06 00:42:55 +08:00
    triplelift
        1
    triplelift  
       Aug 6, 2018 via iPhone   ❤️ 1
    没用过 16 不过这个函数应该是用来代替 componentWillReceiveProps 的 可以思考下之前你使用这个函数的场景 这里的目的一般是基于 props 的内容有选择的更新 state 记住 props 与 state 是组件中独立的两个部分 二者可能有关联但必须分开管理
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5630 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 03:51 · PVG 11:51 · LAX 20:51 · JFK 23:51
    ♥ Do have faith in what you're doing.