我目前正在尝试从react实现井字游戏示例,但使用了hook和ES6标准,但我似乎无法调用useState。我不断收到这些错误:
第6:33行:在函数“游戏”中调用React Hook“ useState”,该函数既不是React函数组件也不是自定义的React Hook函数react-hooks / rules-of-hooks
我当前的版本是:
“反应”:“ ^ 16.12.0”,
“ react-dom”:“ ^ 16.12.0”,
“反应脚本”:“ 3.4.0”
这是我当前的代码:
import React, { useState } from "react";
import Restart from "../../Components/Restart/Restart";
import Square from "../../Components/Square/Square";
const game = () => {
const [squares, setSquares] = useState(Array(9).fill(null));
const [isXNext, setIsXNext] = useState(true);
const nextSymbol = isXNext ? "X" : "O";
const winner = calculateWinner(squares);
...
return (
<div className="container">
);
};
非常感谢!