crane-cloud/frontend

View on GitHub
src/helpers/localStorage.js

Summary

Maintainability
A
0 mins
Test Coverage
F
23%
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) {
    // ingore
  }
};

export const onUnload = () => {
  localStorage.clear();
}