notes/react
React 的学习笔记
什么是 React?
React is a declarative, efficient, and flexible JavaScript library for building user interfaces.
划重点:描述性的,高效的,灵活的用来做界面的框架。
componenet takes props, returns view, through render
view is a React element.
** React.component**
React 可以有很多种 component, react.component 是其中比较基础的一种。
TIPS: When you want to aggregate data from multiple children or to have two child components communicate with each other, move the state upwards so that it lives in the parent component. The parent can then pass the state back down to the children via props, so that the child components are always in sync with each other and with the parent.
划重点:如果有状态要维护,把需要维护的状态放在 parent 里面。
How do I use/include third party libraries in react?
https://stackoverflow.com/questions/45658200/how-do-i-use-include-third-party-libraries-in-react
Redux
React 已经基本学会了,现在需要学习 Redux 。
Redux 里面有几个概念,store,reducer,action
记住一句话,你现在可能看不懂,但是跟我来,把这句话读三遍:
一般来说, action 都是会被 dispatch 的,每次 dispatch 都会 run 所有 reducer,reducer 会 take in 两个参数:state 和当前的 action,而 action 实质上是一个对象,包含动作的 type 和这个动作的相关参数