在我滚动页面之前,React Hooks不会更改对象状态

我是React的新手,并且在渲染组件时遇到问题(“ setBoard”在滚动页面之前不会生效):

const handleKeyDown = useCallback(event => {
if (board.hasWon()) {
  return;
}
if (event.keyCode >= 37 && event.keyCode <= 40) {
  event.preventDefault();
  var direction = event.keyCode - 37;
  setBoard(board.move(direction))
}
  }, [])

useEffect(() => {
  window.addEventListener('keydown', handleKeyDown)
  return() => {window.removeEventListener('keydown', handleKeyDown)}

}, [handleKeyDown])

我的组件没有重新渲染,但是对象“ board”的值正在更改:

return( </div>    <BoardView board={board} /> </div>)

经过一番研究,我发现React比较对象是否已与Object.is更改,并且响应为true,这可能是因为我编写的代码是“ board”:

  Board.prototype.move = function (direction) {
    // 0 -> left, 1 -> up, 2 -> right, 3 -> down
    this.clearOldTiles();
    for (var i = 0; i < direction; ++i) {
      this.cells = rotateLeft(this.cells);
    }
    var hasChanged = this.moveLeft();
    for (var i = direction; i < 4; ++i) {
      this.cells = rotateLeft(this.cells);
    }
    if (hasChanged) {
      this.addRandomTile();
    }
    this.setPositions();
    return this;
  };

也许我应该返回与.move()中的“ return this”不同的东西?

有任何想法吗??? (:

谢谢阅读!