

Yarn add further reference on how to type error and meta, see our type Great discussion and input from everyone! Async is really hard, which is why it was good for Redux to punt on it for a while but its critical for real-world apps. If you find the time, I'd appreciate it if you gave the CodeSandbox build from that PR a try and give feedback in the issue if it works for you now. I'm opening a PR ( #350) to fix this, so you'll be able to use the prepare notation with the next release of RTK.

There was a bug that prevented meta and error from bein typed correctly. Didn't mean to snap - too many meetings today, I'm kinda tired.) (I took offense to your "shit" comment here, but I might have misread your comment, so I'm sorry. It would be really nice if any implementation actually attached these on the meta object instead. My solution/hack was to add a meta object in the payload itself, mostly cause I couldn't figure out the types. My two cents in some practical usage of the above pattern (the types are crap btw, please halp!) is that occasionally I call an API where I need access to the arguments the action was called with in the fulfilled/error cases. Also still early experimental stage atm, but I think there may be a 50%-ish solution there as well that would be of benefit. (And of course, we can bikeshed over the desired action type / function names.)Īs a related note, over in #333 I'm playing around with the idea of adding some prebuilt types and logic to handle working with normalized state. That does mean manually defining the action prefix, but again I think that's an acceptable limitation for the, thoughts on the types in that gist atm? Notionally, you'd call createAsyncAction() up front in a slice file, and then use these action creators in the extraReducers arg for createSlice(). It's still something we could add down the road if desired, but I'd rather move more slowly, since any API that we add is something we have to maintain indefinitely (implementation, documentation, etc). I also particularly like that it's in TS already and relies on RTK APIs and types.įor now, I think I'd want to still skip adding any special option syntax for defining these directly as part of createSlice. All that matters is that the callback you provide returns a promise, and it handles generating the appropriate actions types and doing the action dispatch sequencing.

We allow the user to entirely bring-your-own data fetching and response handling. Example const fetchTodo = createAsyncAction ( 'todos/fetch', ( ) => ) )
