How to create a listening status data?

Good afternoon.
Faced with such a task.

There is a global array which finds the object.The number of this object that is, its index is sent to state as soon as I receive it.
Starting state:
this.state = {
 index: 0,
 data: []
 };

After receiving:
this.state = {
 index: 1,
 data: []
 };


The problem is this. As soon as the index is changed from 0 to 1 I need to send a request via redux on getting the next object from the global array.And so on.As soon as state.index = 2 you need to send a request to receive a 3rd object.

How to do it ?
April 3rd 20 at 17:21
1 answer
April 3rd 20 at 17:23
it is quite suitable for componentDidUpdate()
componentDidUpdate(prevProps, prevState){
 if(prevState.index !== this.state.index){ // check if it is updated we need state
 this.props.getNewObject() 
}
}

Find more questions by tags ReactReact Native