State状态On this pageState状态示例Live Editorclass Clock extends React.Component { constructor(props) { super(props) this.state = {date: new Date()} } componentDidMount() { this.timerID = setInterval(() => { this.setState({date: new Date()}) }, 1000) } componentWillUnmount() { clearInterval(this.timerID) } render() { return ( <div> <h2>当前时间:{this.state.date.toLocaleTimeString()}</h2> </div> ) } }class Clock extends React.Component { constructor(props) { super(props) this.state = {date: new Date()} } componentDidMount() { this.timerID = setInterval(() => { this.setState({date: new Date()}) }, 1000) } componentWillUnmount() { clearInterval(this.timerID) } render() { return ( <div> <h2>当前时间:{this.state.date.toLocaleTimeString()}</h2> </div> ) }}ResultLoading...正确使用所有 State 数据都必须使用 setState 才能更新this.setState({msg: 'Hello'})更新合并State 的更新可能是异步的,出于性能考虑,React 可能会把多个 setState() 调用合并成一个调用。