Taking Advantage of Redux Toolkit for Creating Actions

Learn how to replace Redux reducers with Redux Toolkit slices, handle data fetching using createAsyncThunk, and utilize Redux DevTools for debugging in a React Native app.

Our reducer is very limited so far. We can’t use it directly to fetch data because, as the rules of reducers state, reducers cannot be used to do any asynchronous logic. If we were writing our app sometime around 2018 or 2019, we would probably create a separate actions file, manually configure Redux middleware functions to manage asynchronous API calls, and finally proceed to write the fetching actions. Luckily, we can now take advantage of Redux Toolkit, which comes bundled with all the necessary helper functions and a utility called createSliceIn Redux lingo, a slice is a collection of reducers and actions for a single feature in our app.

Converting reducers to slices

Let’s convert our likedImages reducer into a Redux Toolkit slice:

Get hands-on with 1200+ tech skills courses.