menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Redux Tool...
source image

Dev

1w

read

378

img
dot

Image Credit: Dev

Redux Toolkit: Creating Thunk Functions

  • A thunk function is a function created to handle async logic, like calling an API. It takes two arguments dispatch and getState to dispatch actions and have access to the current state if needed.
  • Redux Toolkit provides the createAsyncThunk API to generate thunks easily. fetchUserById is the thunk function created here.
  • Besides letting you create thunk functions for API calls, createAsyncThunk automatically dispatches actions to track the state of API requests.
  • The extraReducers field in our userSlice is used to handle state status changes.

Read Full Article

like

22 Likes

For uninterrupted reading, download the app