react_devtools_backend.js:4012 A non-serializable value was detected in the state, in the path:
func
. Value: () => console.log("test")
Take a look at the reducer(s) handling this action type: toDosReducer/test.
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)
const testSlice = createSlice({
name: "testReducer",
initialState: {},
reducers: {
test: (state, action) => {
return { func: () => console.log("test") }; // state에 함수를 넣어 Error
},
},
});
// or
console.log(typeof test) // function
dispatch({ type: test, payload: { name:"name" } }); // dispatch의 action type에 함수를 넣어서 Error
import {getDefaultMiddleware} from "@reduxjs/toolkit";
const store = configureStore({
reducer: testSlice.reducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
serializableCheck: false,
})
});
export const printTest = createAsyncThunk("printTest", (state, action) => {
return console.log("test");
});
// Home.jsx
import printTest from "./store.js";
dispatch(printTest()); // "test"
Promises
, Symbols
, Maps/Sets
, functions
, class instances
로 직렬화 할 수 없는 값을 의미한다.공식사이트 관련내용
https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state
https://redux.js.org/style-guide/#do-not-put-non-serializable-values-in-state-or-actions