Y
Y
yankoyski2019-02-04 05:20:42
JavaScript
yankoyski, 2019-02-04 05:20:42

Synchronous ajax request - react?

You must first make a request to the server using ajax, wait for the result, and then draw the page based on the received data. How can it be implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2019-02-04
@yankoyski

first make a request <...> and then render the page

No, this is not how it is done. The page is rendered immediately. While there is no data, a loading indicator is shown; after the request is executed, the indicator is hidden, the data is shown (see conditional rendering ). For example .

A
Andrey Okhotnikov, 2019-02-04
@tsepen

Here's a pretty clear example from the official documentation. Instead of callbacks, you can use async/await , but the essence is the same

P
Petr Vasiliev, 2019-02-04
@danial72

fetch('./api/some.json').then( function(resp){drawResp(resp)})
function drawResp(resp){
BrowserDrawMeBeautiful()
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question