redux sync localstorage state实时

时间:2016-12-08 11:54:03

标签: reactjs redux

我从这段视频中学习如何将状态写入localstorage:
https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage

export const loadState = () => {
  try {
    const serializedState = localStorage.getItem('state');
    if (serializedState === null) {
      return undefined;
    }
    return JSON.parse(serializedState);
  } catch (err) {
    return undefined;
  }
};

export const saveState = (state) => {
  try {
    const serializedState = JSON.stringify(state);
    localStorage.setItem('state', serializedState);
  } catch (err) {
    // Ignore write errors.
  }
};

如果我更改了A' A'选项卡,然后我去了B' B'选项卡并刷新页面,我可以获得我更改的新值' A'标签

但我想知道如何让B' B' tab没有刷新页面获取新值???

0 个答案:

没有答案