L
L
lookingfor22020-12-28 16:31:47
React
lookingfor2, 2020-12-28 16:31:47

How to perform routing after several requests have returned success?

I send several requests on click, how to correctly and beautifully track the success of these requests and then perform some action, for example, routing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Melnikov, 2020-12-28
@lookingfor2

const Component = () => {
  const history = useHistory();

  const handler = async () => {
    await firstRequest();
    await secontRequest();
    await thirdRequest();
    history.push("/myroute");
  }

  return (...);
}

const Component = () => {
  const history = useHistory();

  const handler = async () => {
    await Promise.all([
      firstRequest(),
      secontRequest(),
      thirdRequest(),
    ]);
    history.push("/myroute");
  }

  return (...);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question