React初学之组件基础

学习参考 慕课网-react入门
讲的比较好

React

  1. React并不是一个完整的MVC MVVM框架,只是其中的V部分

  2. React组件化构建UI的思路值得学习

  3. React的特点在于“轻量”,适合复杂场景的高性能开发,组件库的重用和组件的组合

React Components

React组件声明周期如下
《React初学之组件基础》

  1. Mounted: React.renderComponent() react组件被render解析生成对应DOM节点并插入浏览器的DOM结构的一个过程

  2. Update: setState()/setProps() => render() react会将组件的当前state和最近state进行对比,如果发生改变影响DOM结构时候,则被重新render的过程

  3. Unmounted: 一个mounted的react components对应DOM节点被从DOM结构中移除的一个过程

每个状态React都封装了相应地hook函数
《React初学之组件基础》
1) Mounting过程:

getDefaultProps() => getInitialState() => componentWillMount() => render() => componentsDidMount()  

2) Updating过程:

componentWillReceiveProps() 当mounted component将要接受一个新的props时候触发 => shouldComponentUpdate() 判断当前props是否改变 改变则更新=> componentWillUpdate() => render() => componentDidUpdate();

3) Unmounting过程:

componentWillUnmount();

components的state和props的区别?

props在写组件的时候指定,一般情况下不会变;
state一般被认为是私属于当前组件,可以改变。

component事件绑定

两个学习demo
jsx基础
https://jsfiddle.net/lifesimp…

component事件绑定
https://jsfiddle.net/lifesimp…

注意一点,组件名称大写开头

    原文作者:lifesimple
    原文地址: https://segmentfault.com/a/1190000007036519
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞