Error:
index.js:1 A non-serializable value was detected in an action, in the path:
payload.config.transformRequest.0
.
Value: ƒ
transformRequest(data, headers) {
normalizeHeaderName(headers, 'Accept'); normalizeHeaderName(headers, 'Content-Type'); if (utils.isFormData(data) || utils.isArrayBuffer(data) || utils.i…
Slice:
export const getProducts = createAsyncThunk(
'products/getProducts',
async() => {
const res = await axios.get('http://localhost:5000/products/view-products', {withCredentials: true});
return res;
}
)
const getProductsSlice = createSlice({
name : 'products',
initialState : {
list : [],
status : null
},
extraReducers : {
[getProducts.pending] : (state) => {
state.status = 'loading'
},
[getProducts.fulfilled] : (state, {payload}) => {
console.log("produtcts payload: ", payload.data)
state.list = payload.data
state.status = 'success'
},
[getProducts.rejected] : (state) => {
state.status = 'failed'
}
}
})
Inside Component:
const dispatch = useDispatch();
const data = useSelector(state => state.products.list);
console.log("the products are :", data);
useEffect(() => {
dispatch(getProducts());
}, [dispatch]);
Other slices in the app work fine. Having a hard time working around the non-serializable
return res;
should bereturn res.data;
– Pavierreturn res
you'll need to do something likereturn {data: res.data, status: res.status}
– Pavier