I have tried to use yield take(action.type) in my saga.
function* foo() {
console.log('pausing')
yield take(action.type)
console.log('passing')
}
I made sure I dispatched the right action in my useEffect
useEffect(() => {
dispatch(action())
}, [action])
I also made sure the action is dispatched after the saga is set up correctly.
The actions are defined in Redux Toolkit's slice
import { createSlice } from '@reduxjs/toolkit';
const appSlice = createSlice({
name: 'app',
initialState: {},
reducers: {
appMounted: (state) => {
// ... some state updates if needed
},
buttonClicked: (state) => {
// ... some state updates if needed
}
}
});
export const { appMounted, buttonClicked } = appSlice.actions;
export default appSlice.reducer;`
Also the action type I am using in the take effect is the exact same action type I am dispatching.
The issue is that, 'pausing' got printed, but after I dispatch action, passing is not getting printed.
Make sure you add the
redux-sagamiddleware to middleware when creating the redux store.A working example:
store.ts:saga.ts:app.slice.ts:App.tsx:index.tsx:Logs of the console:
codesandbox