React 刷新浏览器 state rudux数据都消失了

当页面刷新之后,redux中的数据会回到初始值,之前存储到redux中的数据也就不复存在了
判断sessionStorage中是否有值,有值的话将sessionStorage中的数据直接付给defaultState,页面刷新之后,由于设置了state = defaultState,页面还是会显示存储数据的。

redux-persist会将redux的store中的数据缓存到浏览器的localStorage中

  

原文地址:https://www.cnblogs.com/zhanglanzuopin/p/12926301.html