redux-persist icon indicating copy to clipboard operation
redux-persist copied to clipboard

Enable `createMigrate` to handle async migrations #866

Open retyui opened this issue 4 years ago • 2 comments

via: https://github.com/rt2zz/redux-persist/issues/806

const migrations = {
  0: (state) => {
    // migration clear out device state
    return {
      ...state,
      device: undefined   
    }
  },
  // You can use also `async () => {}` function
  // For example to move users to other storage
  1: async ({ users, ...state }) => {
    try {
      await insertToOtherStorage(users)

      return state
    } catch (e) {
      // Don't forget about exceptions
      return state
    }
  },
  2: (state) => {
    // migration to keep only device state
    return {
      device: state.device
    }
  }
}

retyui avatar Jul 01 '20 17:07 retyui

Any progress?

AlimovSV avatar May 31 '22 10:05 AlimovSV

cc @ckalika

retyui avatar May 31 '22 10:05 retyui