Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use redux-thunk with redux toolkit?


Asked by Lina Salas on Dec 10, 2021 FAQ



My application dispatches to reducers slices created via the createSlice ( {}) (see createSlice api docs) This so far works brilliantly. I can easily use the built in dispatch (action) and useSelector (selector) to dispatch the actions and receive/react to the state changes well in my components.
In addition,
A thunk function may contain any arbitrary logic, sync or async, and can call dispatch or getState at any time. In the same way that Redux code normally uses action creators to generate action objects for dispatching instead of writing action objects by hand, we normally use thunk action creators to generate the thunk functions that are dispatched.
One may also ask, Redux Toolkit contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications. Because of this, Redux Toolkit is the standard way to write Redux application logic.
Additionally,
So createAsyncThunk takes three params: First the name of your action creator. Second is a async function that will handle the request and return the result. Third is optional that’ll any data you want to pass. You might ask how can I post data?
Also Know,
Action and Reducers are combined in redux toolkit as Slice. To make HTTP API call, we will be using createAsyncThunk. We will discuss about it in detail in the later part of the article.