Using Redux Toolkit’s createAsyncThunk | Advanced React Native | React Native tutorial

preview_player
Показать описание
While a Redux store possesses great state management features, it has no clue how to deal with asynchronous logic. Redux eschews handling asynchronous logic simply because it doesn’t know what you want to do with the data you fetched, let alone if it’s ever fetched — hello, errors. 🙂

Middleware has since been used in Redux applications to perform asynchronous tasks, with Redux Thunk’s middleware being the most popular package. A middleware is designed to enable developers to write logic that has side effects — which refers to any external interaction outside an existing client application, like fetching data from an API.

With Redux Toolkit, Redux Thunk is included by default, allowing createAsyncThunk to perform delayed, asynchronous logic before sending the processed result to the reducers.

According to the official docs: createAsyncThunk is a function that accepts a Redux action type string and a callback function that should return a promise. It generates promise lifecycle action types based on the action type prefix that you pass in, and returns a thunk action creator that will run the promise callback and dispatch the lifecycle actions based on the returned promise.

Within createSlice, synchronous requests made to the store are handled in the reducers object while extraReducers handles asynchronous requests, which is our main focus.

Asynchronous requests created with createAsyncThunk accept three parameters: an action type string, a callback function (referred to as a payloadCreator), and an options object.

#jasacadamy #reactnativecourse #reactnativetutorial #react

1:00 introduction
08:00 Redux toolkit store creation
12:05 Redux slice creation
13:21 createAsyncThunk in Redux-Toolkit
19:21 builder addCase createAsyncThunk in Redux-Toolkit
23:13 Dispatching action
Рекомендации по теме
Комментарии
Автор

very good explaining ... thank U ... we need more tutorial

ashrafKhal-pg