Simplifying Thunks With createAsyncThunk
Get started with the createAsyncThunk utility provided by Redux toolkit, and learn how to simplify the creation of thunks.
We'll cover the following...
Why createAsyncThunk?
If you created 100 thunks for fetching async data, you’ll notice some similar patterns across all of them. Common patterns breed abstractions.
Whenever there are similar patterns, our instinct as developers is to abstract this into a common utility. This is the premise for createAsyncThunk
.
Creating an async thunk is like signing a pact that says you’re going to create an async function and will make some state updates depending on the state of that async action: loading, success, or error.
In that case, think of createAsyncThunk
as a template generator for that signed pact.
It abstracts the standard recommended RTK approach for handling async requests by ...