react(2)--Thinking in React

来源:互联网 发布:java使用ftp上传文件 编辑:程序博客网 时间:2024/06/06 04:59

Thinking in React

需要掌握几个react的重要概念,props,states,其中的state概念特别重要。下面就从确定哪些变量是state,以及确定state的层级位置:

找到state变量:

step1:整个组件分解组件成为若干独立小组件。
step2:然后ask yourself three questions:

* is it passed into the component frome parent via props?if it is ,it isn`t state
* does it change over the time? if it is ,it is state.
* does it can be computed by other state and props?if it is ,it isn`t state

确定state的层级位置

1) 找出所有需要依据状态渲染的组件;
2)找出1)中所有的组件的共同最近父组件A;
3)共同最近父组件A以或者组件A以上的组件必须要拥有这个状态。
3)如果不能找到一个拥有该状态的组件,那么就添加一个组件B,该组件B只是用来维系这个状态。组件B位于最近父组件A之上。

入门基础ppt-ant

react最佳实践,好多名词都没听说过,一个一个击破

0 0