Y
Y
Yzurgzd2020-08-12 16:18:15
React
Yzurgzd, 2020-08-12 16:18:15

What is the correct way to call action in Ract Redux?

There is a url filter on the back: "/list/?genres=&page=&search=&favorite=&ordering="

Should I add all the parameters to the action url at once or would it be better to do something else?

export const get = (genre, page, search, favorite, ordering) => (
  dispatch
) => {
  const url = `${API_URL}/list/?genres=${genre}&page=${page}&search=${search}&favorite=${favorite}&ordering=${ordering}`;

  axios
    .get(url)
    .then((res) => {
      dispatch({
        type: GET,
        payload: res.data,
      });
    })
    .catch((err) => console.log(err));
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2020-08-12
@Yzurgzd

Yep, just like this

const params = { search: 3 }; // условно, тут все ваши параметры
axios
    .get(url, params)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question