React知识点汇总
getInitialState  获取默认statecomponentWillMount  即将挂载render   挂载componentDidMount  组件渲染完成,可以在这里执行DOM操作等shouldComponentUpdate  是否重新渲染,当返回true,表示渲染;否则不渲染,也就是不调用rendercomponentWillUpdate   即将重新渲染render   渲染componentDidUpdate  重新渲染完成setState()来更新状态。setState()做了优化,也就是每次队列循环中,都会合并所有setState(),且只会渲染(render)一次。props来通信componentWillReceiveProps(nextProps) {   
  if ('name' in nextProps && this.props.name !== nextProps.name)    {   
     this.setState({   
       name: nextProps.name   
      })   
  }  
}
class ChildComponent {
  render() {
    return (
      <div> <button onClick={this.props.onClick}>Button</button> </div>
    );
  }
}
class ParentComponent {
  state = {
    count: 0
  }
  onClick = () => {
    this.setState({
      count: this.state.count + 1
    })
  }
  render() {
    return (
      <div> <ChildComponent onClick={this.onClick}/> </div>
    );
  }
}
createStore()
const DO = 'DO';   
function do() {   
  return {   
    type: DO   
  }  
}
const defaultState = {   
  count: 1  
};   
function myData(state = defaultState, action) {   
  switch (action.type) {   
    case DO:   
      return {...state, ...{count: state.count + 1}};   
  }  
}
import * as React from 'react';   
class MyComponent extends React.Component {   
  static defaultProps = {   
    name: ''   
  };    
  
  constructor(props) {   
    super(props);   
    this.state = {};   
  }    
  componentDidMount() {}    
  render() {   
    return (<div>abc</div>);   
  }  
}
8、常用方法
React.createElement(type, [props], [...children]) 创建React元素
React.cloneElement(element, [props], [...children]) 克隆并生成一个新元素
React.isValidElement(object)   验证对象是否是一个React元素。返回 true 或 false 。
React.Children  
map 遍历子元素,映射为一个新的子元素集合(跟 ES5 的 Array.map 差不多)
forEach 遍历子元素,对每一个子元素执行回调,但是不返回一个新数组(跟 ES5 的 Array.forEach 差不多)
count 返回子元素的总数
only 返回 children 中的唯一子集。否则抛出异常。
  toArray  将 children 不透明数据结构作为一个平面数组返回,并且 key 分配给每个子集。
