How do I get multi-request data in a Redux action creator and then send the collected data to a reducer?

I am using twich api to get base channels information and check if the channel is leaking.

I need to make two separte requests to collect this data.

I wanted to do it with axioms like this:

export function fetchUser(user_id) {
  const get_user = `${ROOT_URL}/users/${user_id}?client_id=${CLIENT_ID}`;
  const get_stream = `${ROOT_URL}/streams/${user_id}?client_id=${CLIENT_ID}`;

  function getUserInfo() {
    return axios.get(get_user);
  }

  function getUserStream() {
    return axios.get(get_stream);
  }

  axios.all([getUserInfo(), getUserStream()])
    .then(axios.spread(function (infos, streams) {
      //WHAT TO DO HERE?
    }));

  return {
    type: FETCH_USER,
    payload: req,
  };
}

      

The problem is that redux-promis middleware only converts one simple Promise obj to a simple obj for the reducer and I cannot send an array with two promises as a payload.

How can I set up this code to send both query results to the reducer so that my state is updated as a normal obj instead of the obj promise? Miba somehow with redux-stupid? I want to point out that I am completely new in this matter, so I would like to ask for leniency :)

+3


source to share


1 answer


The good news is that you can install anything in the payload (including the object). So it would be convenient:



return {
    type: FETCH_USER,//change constant here with appropriate action type
    payload: {infos:infos,streams:streams}
};

      

+1


source







All Articles