peterkarn / vue-kanban-hierarchical

0 stars 0 forks source link

Wrong way to sync store with localstorage #2

Open zpwebbear opened 2 years ago

zpwebbear commented 2 years ago

You invoke the mutation on App.js component beforeCreate hook https://github.com/peterkarnaukhsite/vue-kanban-hierarchical/blob/05dc4f76981778966ee8f1c57c0e496f443411cd/src/App.vue#L19

But it is the wrong way. You need to get data from the localstorage on the vuex creation. E.g

const defaultState = {
    nextBoadrId: 0,
    nextColId: 0,
    nextTaskId: 0,
    boards: [],
}

function getLocalStorageState(){
  return JSON.parse(localStorage.getItem("store")) ?? defaultState;
}

const store = createStore({
  state: getLocalStorageState(),
  //... other state lines
peterkarn commented 2 years ago

Used your approach but i`ll be thankfull if you comment why my aproach could be buggy or inapropriate?