I would like to know how to use redux sagas with react hooks, how does redux get implemented, is there any unique use cases to know about?
Should I be using the regular react dispatch?
I would like to know how to use redux sagas with react hooks, how does redux get implemented, is there any unique use cases to know about?
Should I be using the regular react dispatch?
I had difficulty finding this information out, so I created a project for it to better understand how to use the hooks with sagas.
https://github.com/KevinDanikowski/react-sagas-with-hooks-pokemon-sample-app
In particular, this code block will be the most useful, everything else is just the same implementation of regular redux.
...
const dispatch = useDispatch();
const pokemon = useSelector(state => {
return state.pokemons.find(pokemon => pokemon.id === pokemonId)
});
const callPokemon = useCallback(
() =>
dispatch({
type: `GET_POKEMON${useSaga ? '_SAGA':''}`,
pokemonId
}),
[dispatch, pokemonId, useSaga],
)
useEffect(() => {
const getPokemon = () => callPokemon();
getPokemon();
}, [callPokemon])
...