I just started exploring react-redux hooks and I was curious how to return a promise if I am using thunk and useDispatch()
. Essentially I want to achieve the following:
const dispatch = useDispatch();
dispatch(myAction(...args)).then((result) => {
...do something with result
});
When my action looks like this:
const myAction = (arg1, arg2) => {
return (dispatch, getState) => {
Promise.resolve(arg1 + arg2);
}
}
I've simplified my problem a lot, but that is essentially what I'm dealing with. When I try to dispatch the above action, I get the error dispatch(...).then
is not a function.
I know redux hooks are pretty new, but I was curious if anybody had gotten this to work or would know a solution. I feel like it should be relatively easy to make this work, but I am at a loss. If you need any more information, let me know. Thanks in advance for any help!