D
D
Daniil Sugonyaev2018-08-20 21:41:11
React
Daniil Sugonyaev, 2018-08-20 21:41:11

How to request data on page load?

When I go to the page, I need to get data via the API. But it is not entirely clear how to initialize the request in the best way. I called the API in componentDidMount() and sent it to the state, but this causes the component to be re-rendered and is considered undesirable in the docks. What is the best thing to do in this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-20
@coolswood

I called the API in componentDidMount() and sent it to the state, but this causes the component to be re-rendered and is considered undesirable in the docks.

What docks is this? In those that are known to me, this is expressly recommended:
You should populate data with AJAX calls in the componentDidMount lifecycle method. This is so you can use setState to update your component when the data is retrieved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question