0

I'm using React JS.

At First, I need to fetch data from database using REST API and with this results, I'm setting some variables which further I'm passing to another class. Now I want to make a synchronous request through axios so that only after setting data control should go next. In short, I want to stop rendering my code till my variables will set to data. How to achieve this through axios?

Vikrant
  • 4,920
  • 17
  • 48
  • 72
Nitesh
  • 823
  • 1
  • 10
  • 15

1 Answers1

4

In React there is no way in doing this. This is intentional. You should think about how to handle this.

The obvious choice here is to show a loading indicator or any other form of output to render while you waiting for the response.

After you receive your response you can set the state in order to rerender your component and show the desired output.

dknaack
  • 60,192
  • 27
  • 155
  • 202