How to log action created by createAsyncThunk? #3807
-
I created a middleware like this export const loggerMiddleware: Middleware = () => (next) => (action) => {
console.log(action.type, { payload: action.payload })
next(action)
} And my store setup is: export const store = configureStore({
reducer: {
counter: counterReducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: false,
}).concat(loggerMiddleware)
}) I have a thunk created: const fetchSomeData = createAsyncThunk(
'api/fetchSomeData',
async (arg) => {
// call api to get data
}
) When I call Is logging thunk supported? |
Beta Was this translation helpful? Give feedback.
Answered by
EskiMojo14
Oct 18, 2023
Replies: 1 comment 2 replies
-
are you dispatching fetchSomeData? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
okay, you've edited - the behaviour you're seeing is correct.
'api/fetchSomeData'
is a prefix, createAsyncThunk creates pending/fulfilled/rejected actions based on it.also, your middleware has a bug - remember to return
next(action)
, otherwise you break other middlewares' ability to return values.