简体   繁体   English

页面刷新后如何保存状态?

[英]How to save state after page refresh?

I have a button when I click on it with:当我点击它时,我有一个按钮:

this.props.history.push("/dashboard");

I render another component, but at the same time my state is saved.我渲染了另一个组件,但同时我的状态被保存。 But if I reload the page with f5, my state is lost and I can't load the correct data.但是如果我用 f5 重新加载页面,我的状态就会丢失,我无法加载正确的数据。 Those.那些。 the state of the current component depends on another, how can I save this state upon reboot?当前组件的状态取决于另一个组件,如何在重新启动时保存此状态? localstorage does not quite fit localstorage 不太适合

You have to use localStorage.您必须使用 localStorage。

If you use Redux, It's best to do the following: use redux-persist如果你使用 Redux,最好执行以下操作:使用redux-persist

also you can see:你也可以看到:

question: How do I store my state in localstorage in my Redux application?问题: 如何在 Redux 应用程序的 localstorage 中存储我的状态?

you can see answer this question你可以看到回答这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM