Answer the question
In order to leave comments, you need to log in
How to use useDispatch with redux-thunk?
I use new hooks from react-redux - useDispatch .
How can I call my asynchronous function through this hook in which dispatch will be available, like that
const func = (data) => async (dispatch) => {
//code...
}
Answer the question
In order to leave comments, you need to log in
dispatch your function is derived from redux-thunk. Here .
UseDispatch example:
const Foo = ({ data }) => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(func(data));
}, [data]);
return (/* ... */);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question