[英]Can't call useState hook in arrow function
Im currently trying to implement the tic tac toe example from react but using hooks and ES6 standards but I cant seem to be able to call useState.我目前正在尝试从 react 实现井字游戏示例,但使用钩子和 ES6 标准,但我似乎无法调用 useState。 I keep getting these errors:我不断收到这些错误:
Line 6:33: React Hook "useState" is called in function "game" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks第 6:33 行:在函数“game”中调用 React Hook “useState”,它既不是 React 函数组件,也不是自定义 React Hook 函数 react-hooks/rules-of-hooks
My current versions are:我目前的版本是:
"react": "^16.12.0", “反应”:“^ 16.12.0”,
"react-dom": "^16.12.0", "react-dom": "^16.12.0",
"react-scripts": "3.4.0" “反应脚本”:“3.4.0”
This is my current code:这是我当前的代码:
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">
);
};
Thanks a lot!非常感谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.