标签:document int ntb nbsp color dom reac tps class
1、一个demo(https://www.reactjscn.com/docs/state-and-lifecycle.html)
class Clock extends React.Component { constructor(props) { super(props); this.state = {date: new Date()}; } componentDidMount() { this.timerID = setInterval( () => this.tick(), 1000 ); } componentWillUnmount() { clearInterval(this.timerID); } tick() { this.setState({ date: new Date() }); } render() { return ( <div> <h1>Hello, world!</h1> <h2>It is {this.state.date.toLocaleTimeString()}.</h2> </div> ); } } ReactDOM.render( <Clock />, document.getElementById(‘root‘) );
2、demo: 兄弟组件之间通信,使用到生命周期钩子componentWillReceiveProps
标签:document int ntb nbsp color dom reac tps class
原文地址:https://www.cnblogs.com/xy-ouyang/p/12034424.html