Javascript ReactJS中的localStorage

Javascript ReactJS中的localStorage,javascript,reactjs,local-storage,Javascript,Reactjs,Local Storage,请帮助解决我的问题 我有一个反应成分。我在其中一个函数中设置了间隔 我想要:重新加载页面组件后应继续工作(setInterval正在运行,所有状态都在更新) 如何使用localStorage实现这一点 我试图保存所有的状态,但setInterval停止了工作,这不是我需要的 我的密码是贝娄 类秒表扩展了React.Component{ 构造函数(){ 超级(); 此.state={ 开始时间:空, endTime:null, isRunning:null, 当前时间:0, } } 格式化时间=

请帮助解决我的问题

我有一个反应成分。我在其中一个函数中设置了间隔

我想要:重新加载页面组件后应继续工作(setInterval正在运行,所有状态都在更新)

如何使用localStorage实现这一点

我试图保存所有的状态,但setInterval停止了工作,这不是我需要的

我的密码是贝娄

类秒表扩展了React.Component{
构造函数(){
超级();
此.state={
开始时间:空,
endTime:null,
isRunning:null,
当前时间:0,
}
}
格式化时间=(时间)=>{
const formattedTime=新日期(时间);
让hours=formattedTime.getUTCHours().toString();
让分钟数=formattedTime.getMinutes().toString();
设秒=格式化的时间。getSeconds().toString();
如果(hours.length<2){hours=`0${hours}`;}
如果(minutes.length<2){minutes=`0${minutes}`;}
如果(seconds.length<2){seconds=`0${seconds}`;}
返回(`${hours}:${minutes}:${seconds}`)
}
updateStopWatch=()=>{
让updateTime=this.state.currentTime+1000
console.log(updateTime)
这是我的国家({
currentTime:UpdateTime
})
}
startStopWatch=()=>{
让startTime=Date.now();
这是我的国家({
开始时间:开始时间,
当前时间:0,
isRunning:是的,
runClock:setInterval(this.updateStopWatch,1000)
})
}
秒表=()=>{
让endTime=Date.now();
这是我的国家({
endTime:endTime,
isRunning:false,
})
clearInterval(this.state.runClock)
}
渲染=()=>{
//console.log(this.state.isRunning)
返回(
{this.formatingTime(this.state.currentTime)}
开始
停止
)
}
}
ReactDOM.render(,document.getElementById('root'))

这是我认为对你有用的东西

我编辑了你的剪报。它以前不工作,因为根div和react丢失。