Redux Thunk passes dispatch to actions, which allows us to create asynchronous actions. We'll use Redux Thunk to create an action that can load the todos from the http server, and then dispatch the setTodos action with the result of that call.
Thunks can significantly clean up components, because they provide a way to centralize and reuse complex action logic.
Summary of Content:
- Create new
loadTodosmethod that will pull from items from the HTTP server
- Install Redux Thunk
- Setup Redux Thunk as Redux middleware
- Return a thunk from loadTodos, which allows us to wait for the result from the http server before dispatching the setTodos action.
- Simplify the TodoList componentDidMount method by calling loadTodos