0

I've changed the state here by dropping a object inside players. but it seems the state is not changed instantly? Is it a feature or a bug I made somewhere else?

console.log("Before(length):"+this.state.players.length);
players=players.filter(player => player.id !== id2);}
this.setState({players});
console.log("After(length):"+this.state.players.length);

the result is

Before(length):6
After(length):6

which should be 5 afterwards?

Shukai Ni
  • 457
  • 2
  • 6
  • 17

1 Answers1

1

Think of setState() as a request rather than an immediate command to update the component. For better perceived performance, React may delay it, and then update several components in a single pass.

https://facebook.github.io/react/docs/react-component.html#setstate

arturkin
  • 958
  • 1
  • 6
  • 19