组件类定义html
static defaultProps = {}react
static propTypes = {}缓存
constructor(props){...}异步
componentWillMount() // 只执行一次,初始化数据函数
render() // 第一次调用,渲染界面this
componentDidMount() // 只执行一次,执行异步代码spa
componentWillUpdate()code
render() // 每当状态机的数据改变都会自动调用component
componentDidUpdate()htm
componentWillUnmount() // 将要卸载组件以前
一个对象从生到死的过程
用于初始化组件状态
在组件挂载以前调用一次。返回值将会做为 this.state的初始值
用于设置组件的 state 中 属性的默认值
在组件类建立的时候调用一次,而后返回值被缓存下来。
若是父组件没有指定 props 中的某个键,则此处返回的对象中的相应属性将会合并到 this.props (使用 in 检测属性)
getDefaultProps() { return { title: '', popEnabled:true }; },
验证传入到组件的 props
当组件被渲染到 DOM,该方法返回 true,不然返回 false
该方法一般用于异步任务完成后修改 state 前的检查,以免修改一个没有被渲染的组件的 state
当该方法被回调的时候,会检测 this.props 和 this.state,并返回一个单子级组件。
该子级组件能够是虚拟的本地 DOM 组件
也能够返回 null
或者 false
来代表不须要渲染任何东西: 此时 this.getDOMNode() 将返回 null
在整个生命过程当中某个特定时刻会自动调用相应的回调函数 (来通知你)
第一次 render() 以前,执行一次
componentWillMount() // 通常在此 准备数据
第一次 render() 以后,执行一次
componentDidMount() // 执行异步代码 (定时器)
重写如下方法,在组件移除以前,清除定时器
componentWillUnmount()
ReactDOM.unmountComponentAtNode(document.getElementById(""));