From the course: Building Modern Projects with React
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Async thunks
- [Instructor] Now that we've seen all the endpoints of our Todos API, let's hook up our React application to this server by using thunks. The first thing we'll do is open up our thunks.js file. And we're going to create a new thunk. We'll say export const and we'll call this one loadTodos and it won't take any arguments and it'll return an async function which you're allowed to do here. And we're going to put our loading logic into this thunk. So before we implement the body of this async function that we're returning, there's something you should know about thunks. The function we return here gets passed two arguments when the thunk is triggered. And those two arguments are dispatch, which we can use to dispatch other redux actions from inside our thunk, and getState, which is a function that we can use to get access to the current state of the redux store. These two arguments are quite useful. In this particular thunk…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Why do you need Redux Thunk?1m 57s
-
(Locked)
How does Redux Thunk work?2m 51s
-
(Locked)
Adding Redux Thunk to React2m 30s
-
(Locked)
Creating a thunk3m 30s
-
(Locked)
The Todos API2m 18s
-
(Locked)
Async thunks5m 56s
-
(Locked)
Adding another reducer7m 19s
-
(Locked)
Refactoring the todos reducer2m 50s
-
(Locked)
Using thunks to create server resources5m 58s
-
(Locked)
Using thunks to delete server resources4m 46s
-
(Locked)
Challenge: Using thunks to update server resources1m 14s
-
(Locked)
Solution: Using thunks to update server resources3m 34s
-
-
-
-
-