...

/

Chaining Network Requests

Chaining Network Requests

Learn the importance of chaining responses.

We'll cover the following...

Sometimes to fetch data from the server, we have to make chained API calls. A simple example might be fetching the metadata of the current user and then the user’s actual profile from different endpoints. Here’s an example using an asynchronous action creator with redux-thunk:

const fetchCurrentUser = () => dispatch =>
 axios.get(`/user`)
  .then(({ data: user }) => {
    dispatch(setUser(user));

    // Get user's profile
    axios.get(`/profile/${user.profileId}`)
      .then(({ data: profile }) => dispatch(setProfile(profile)));
    }
  );

The ...