From ba6544ba538102182f8f019f4c4ec0c3cc469196 Mon Sep 17 00:00:00 2001 From: ZauberNerd Date: Sat, 8 Jul 2023 11:24:04 +0200 Subject: [PATCH] Fix non-serializable error message Using Redux Toolkit together with redux-persist requires some additional configuration to disable the non-serializable error message: https://redux-toolkit.js.org/usage/usage-guide#use-with-redux-persist --- app/src/store/index.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/store/index.ts b/app/src/store/index.ts index 1870901..19833b1 100644 --- a/app/src/store/index.ts +++ b/app/src/store/index.ts @@ -1,11 +1,20 @@ import { configureStore } from '@reduxjs/toolkit'; import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'; +import { + FLUSH, + PAUSE, + PERSIST, + PURGE, + REGISTER, + REHYDRATE, + persistReducer, + persistStore, +} from "redux-persist"; import storage from 'redux-persist/lib/storage'; -import { persistReducer, persistStore } from 'redux-persist'; import messageReducer from './message'; -import uiReducer from './ui'; import settingsUIReducer from './settings-ui'; import sidebarReducer from './sidebar'; +import uiReducer from './ui'; const persistConfig = { key: 'root', @@ -26,12 +35,18 @@ const persistMessageConfig = { const store = configureStore({ reducer: { - message: persistReducer(persistMessageConfig, messageReducer), + message: persistReducer>(persistMessageConfig, messageReducer), ui: uiReducer, settingsUI: settingsUIReducer, - sidebar: persistReducer(persistSidebarConfig, sidebarReducer), + sidebar: persistReducer>(persistSidebarConfig, sidebarReducer), }, -}) + middleware: (getDefaultMiddleware) => + getDefaultMiddleware({ + serializableCheck: { + ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER], + }, + }), +}); export type RootState = ReturnType; export type AppDispatch = typeof store.dispatch;