我正在用React Hooks重写一个类组件(因为它更干净),但我面临一个问题。在我的类组件中,我有一个对this.setState({B: "blah blah blah"}, () => {//do some function with state A})的回调函数,这样每次状态, [myFunction])
const myFunction = useCallback(() => {console.log(`${A} and $
我目前正在构建一个TicTacToe游戏,并希望将我当前的玩家存储在状态为currentPlayer。在一个玩家移动后,我将currentPlayer更新为另一个播放器。但是,当我尝试将新状态记录到控制台时,它不会产生更新状态的值。nextPlayer, console.log ('userDidMove changed state with ',this.state.currentPlayer)任何帮助找出如何让这个函数返回更新的状态值都是很棒的