C
C
chelkaz2018-11-03 15:08:47
React
chelkaz, 2018-11-03 15:08:47

React why is there an infinite request?

I need to transfer the Data (sections for the menu) to the SearchTree component when loading.
If I pass it like this, then there is a constant update every second.
This is the App component:

...
        <SearchTree sections={store.dispatch(fetchAllSections())} store={store} />
...

And if I pass in the parent to index.js where the store is declared, then everything is OK:
store.dispatch(fetchAllSections());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Laud, 2018-11-03
@kshshe

When mounting the SearchTree component, data is requested from the server and passed to it. Moreover, they are passed in the store parameter, and not in sections. After the data has arrived, the component containing the SearchTree is re-rendered and the data is requested again. And so endlessly.
It’s worth making a method like getData in the App component, where you can request data once when mounting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question