【发布时间】:2021-03-23 22:45:06
【问题描述】:
我正在尝试部署一个反应应用程序。该代码/应用程序在我的本地端运行良好。但是,当我尝试部署它时,我收到此错误:React Hook useEffect has a missing dependency: 'endGame'. Either include it or remove the dependency array react-hooks/exhaustive-deps
这是与错误相关的代码:
useEffect(() => {
if (isTimeRunning && timeRemaining > 0) {
setTimeout(() => {
setTimeRemaining((time) => time - 1);
}, 1000);
} else if (timeRemaining === 0) {
// eslint-disable-next-line react-hooks/exhaustive-deps
return endGame();
}
}, [timeRemaining, isTimeRunning]);
我尝试了几件事,包括将 endGame() 函数添加到数组(作为 useEffect 的第二个参数),但这样做会破坏我的应用程序。
要查看整个代码/项目,请转到 repo,这里:https://github.com/umbur/SpeedTypingGame
附言在将此问题标记为不相关或类似之前,请询问我更多详细信息,谢谢!
【问题讨论】:
标签: reactjs deployment react-hooks use-effect react-functional-component