Answer the question
In order to leave comments, you need to log in
How to create a data state listener?
Good afternoon.
Faced such task.
There is a global array in which it finds an object. The number of this object, that is, its index , is sent to the state as soon as I receive it.
Start state:
this.state = {
index: 0,
data: []
};
this.state = {
index: 1,
data: []
};
Answer the question
In order to leave comments, you need to log in
componentDidUpdate() is fine for this.
componentDidUpdate(prevProps, prevState){
if(prevState.index !== this.state.index){ // проверяем, что обновился именно нужный нам state
this.props.getNewObject()
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question