Estoy tratando de persistir en todos los estados, espero algunas propiedades que no quiero en una tienda redux, las almaceno en una matriz, el reductor se ve así
export interface NoteI { id?: number | Date; header?: string; note?: string; date?: Date; selectStatus?: boolean; /// i want to keep this false everytime i reload the app } let NoteList: NoteI[] = []; const noteReducer = createSlice({ name: "note", initialState: NoteList, reducers: { addNote: (state, action: PayloadAction<NoteI>) => { const newNote: NoteI = { id: new Date(), header: action.payload.header, note: action.payload.note, date: new Date(), selectStatus: false, }; state.push(newNote); }, removeNote: (state, action: PayloadAction<NoteI>) => { return state.filter((item) => item.selectStatus !== true); }, toggleSelect: (state, action: PayloadAction<NoteI>) => { return state.map((item) => { if (item.id === action.payload.id) { return { ...item, selectStatus: !item.selectStatus }; } return item; }); }, loadDefault: (state) => { return state.map((item) => { return { ...item, selectStatus: false }; }); }, editNote: (state, action: PayloadAction<NoteI>) => { return state.map((item) => { if (item.id === action.payload.id) { return { ...item, note: action.payload.note, header: action.payload.header, date: action.payload.date, }; } return item; }); }, }, }); export default noteReducer.reducer; export const { addNote, removeNote, editNote, toggleSelect, loadDefault } = noteReducer.actions;
Ahora quiero que cada vez que cierre la aplicación, todo el estado permanezca igual, excepto selectStatus
La tienda se verá así:
const reducer = combineReducers({ note: noteReducer, }); const persistConfig = { key: "root", storage: AsyncStorage, blacklist: [], }; const persistedReducer = persistReducer(persistConfig, reducer); const store = configureStore({ reducer: { persistedReducer, toggle: toggleReducer }, middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: false, }), }); export default store; export type RootState = ReturnType<typeof store.getState>; export type AppDispatch = typeof store.dispatch; export const persistStorageNote = persistStore(store);
Escuché sobre la blacklist
en redux-persist, pero el ejemplo solo apple para el estado no es una matriz como esta. Ayuda por favor muchas gracias