I am creating an application with react. I have to fetch several data. This is my fetch statement:
const [periods] = useFetch('/company/' + slug + '/waterfall?colIndexOffset=6 ');
At the end of the line, it is a 6 but I have this kind of problem. I have periods and these periods are changed for every object.
const [period_waterfall] = useFetch('/company/' + firminfo.code + '/periods');
I call the period from there and I find the length of periods like this:
var length = period_waterfall.periods.length
I should call this periods fetch multiple times (number of length).
I tried this:
for (let i = 0; i < length; i++) {
my_array.push(useFetch('/company/' + slug + '/waterfall?colIndexOffset=' + i))
}
But it gives error: React Hook "useFetch" may be executed more than once. Possibly because it is called in a loop.
How can I handle it?