createAsyncThunkintermediateextraReducers: builder => {
builder
.addCase(fetchData.pending, state => { state.loading = true })
.addCase(fetchData.fulfilled, (state, action) => {
state.loading = false
state.data = action.payload
})
}The pending action is dispatched synchronously before the async work starts β ideal for showing a loading spinner.
The pending action fires immediately when a thunk is dispatched. Use it to show a loading indicator.
Challenge: Add a loading state that becomes true on pending and false on fulfilled.
dataSlice.reducer(undefined, fetchData.pending('req'))
// β { loading: true, value: null }