As you can see in documentation
This rule should prevent usage of this.state inside setState calls. Such usage of this.state might result in errors when two state calls are called in batch and thus referencing old state and not the current state. An example can be an increment function:
function increment() {
this.setState({value: this.state.value + 1});
}
If these two setState operations is grouped together in a batch it will look be something like the following, given that value is 1:
setState({value: 1 + 1})
setState({value: 1 + 1})
This can be avoided with using callbacks which takes the previous state as first argument:
function increment() {
this.setState(prevState => ({value: prevState.value + 1}));
}
So this is why you have that rule, to avoid erros like this example.
In your case, what you should do is
handleSelect({ nativeEvent }) {
if (nativeEvent == null) {
this.setState(previousState => ({
...previousState,
selectedEntry: nativeEvent
}));
} else {
this.setState(previousState => ({
...previousState,
selectedEntry: JSON.stringify(entry),
markerIsEnabled: true
}));
}
}
But for your case, this an error won't happen because you don't have two consecutives setState
and also, ...this.state
or ...prevState
won't make any diference because you aren't using the previous state to set a new state.
So for the code you provided in your question, just remove ...this.state
and it will work fine, with no errors.