react(2)--Thinking in React

前端之家收集整理的这篇文章主要介绍了react(2)--Thinking in React前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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最佳实践,好多名词都没听说过,一个一个击破

原文链接:https://www.f2er.com/react/307220.html

猜你在找的React相关文章