createAsyncThunkintermediateconst { createAsyncThunk } = ReduxToolkit
const fetchUser = createAsyncThunk('user/fetch', async (id) => {
const res = await fetch('/api/users/' + id)
return res.json()
})
fetchUser.fulfilled.type // β 'user/fetch/fulfilled'createAsyncThunk wraps an async function and automatically dispatches pending/fulfilled/rejected lifecycle actions.
createAsyncThunk(type, payloadCreator) creates an async action creator that automatically dispatches pending, fulfilled, and rejected actions around the async operation.
Challenge: Create a fetchUser thunk and handle its fulfilled case in a slice.
fetchUser.fulfilled.type // β 'user/fetch/fulfilled'