React应用程序设计过程中如何区分模块到底是state还是props?

根据官方文档,满足以下任意条件的模块,就不是State,原文如下:

1、Is it passed in from a parent via props? If so, it probably isn’t state.

2、Does it remain unchanged over time? If so, it probably isn’t state.

3、Can you compute it based on any other state or props in your component? If so, it isn’t state.

即:

  1. 如果是由props传递过来的,那么该模块就不是一个state;
  2. 如果所时间保持不变,那么该模块就不是一个state;
  3. 如果可以根据任何一个state或props来计算得出,那么该模块就不是一个state;

我上面的表述可能有些不恰当,我这里说的【模块】,请尽量理解为开发过程中我们划分出来的独立功能区域。

 

官方地址:https://reactjs.org/docs/thinking-in-react.html

 

posted @ 2018-03-27 15:29  lishidefengchen  阅读(295)  评论(0编辑  收藏  举报