我一直在尝试使用React,并拥有以下时间组件,它只会将Date.now()
渲染到屏幕上:
import React, { Component } from 'react';
class TimeComponent extends Component {
constructor(props){
super(props);
this.state = { time: Date.now() };
}
render(){
return(
<div> { this.state.time } </div>
);
}
componentDidMount() {
console.log("TimeComponent Mounted...")
}
}
export default TimeComponent;
从 React 的角度来看,每秒更新组件以重新绘制时间的最佳方法是什么?
react-interval-rerender
。 - Andy