useAsyncReducerAtom - async dispatch #1136
-
How can I use async dispatch with useReducerAtom?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Looks good. You want to try |
Beta Was this translation helpful? Give feedback.
-
I was able to make this work using TypeScript. Just posting my code here because it might help someone else looking for something similar. I'm sure there must be better ways of doing this, but the following code did the job for me -
Now in your react component use it something like this -
For additional context, my reducer looks like this -
|
Beta Was this translation helpful? Give feedback.
Looks good. You want to try
atomWithAsyncReducer
instead.We don't have a plan to add it in
jotai/utils
, but advanced-recipes docs is an option.Alternatively, you can develop a third-party library.