Asynchronous Action Creators
Explore how to manage server communication in Redux with asynchronous action creators using redux-thunk. Understand common challenges like code duplication, error handling, and testing complexity. Learn why moving async code to middleware keeps action creators simple, making your Redux code easier to debug and maintain.
We'll cover the following...
We'll cover the following...
Let’s start by looking at a server communication implementation with async action creators using the redux-thunk library to understand the underlying pitfalls of this approach:
const fetchUser = id => dispatch =>
axios.get(`http://api.ourserver.com/user/${id}`)
.then(({ data: userData }) => dispatch(setUserData(userData)));
...