Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript (React.js)为什么状态不会立即改变?_Javascript_Reactjs_Frontend - Fatal编程技术网

Javascript (React.js)为什么状态不会立即改变?

Javascript (React.js)为什么状态不会立即改变?,javascript,reactjs,frontend,Javascript,Reactjs,Frontend,我改变了这里的状态,在播放器中放置了一个对象。但似乎状态并没有立即改变?这是我在其他地方做的一个特性还是一个bug 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.len

我改变了这里的状态,在
播放器中放置了一个对象。但似乎状态并没有立即改变?这是我在其他地方做的一个特性还是一个bug

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);
结果是

Before(length):6
After(length):6
之后哪一个应该是5

将setState()视为请求,而不是对 更新组件。为了获得更好的感知性能,可能会做出反应 延迟它,然后在一次过程中更新几个组件


此问题有多个重复项。