Open
Conversation
Replace invalid useEngine() call inside setTimeout callback with a state-based approach using pendingHistory + useEffect pattern. This fix addresses the ESLint error: "React Hook useEngine cannot be called inside a callback" Changes: - Add pendingHistory state to store history awaiting restoration - Add useEffect to monitor engine switch and auto-restore history - Remove setTimeout with invalid Hook call from onConfirm callback
Contributor
|
@phaseddd is attempting to deploy a commit to the liujuntao123's projects Team on Vercel. A member of the Team first needs to authorize it. |
- 添加 node_modules/** 到忽略列表,避免检查依赖包 - 指定 lint 命令只检查 app/components/hooks/lib 目录 - 禁用 Next.js 16+ 过于严格的 React Compiler 规则 - react-hooks/preserve-manual-memoization - react-hooks/set-state-in-effect - react-hooks/immutability - 将 exhaustive-deps 改为 warn 级别
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
改动内容
pendingHistory状态,用于保存待恢复的历史记录useEffect,监听引擎类型切换完成后自动恢复历史记录onConfirm回调中使用setTimeout非法调用 Hook 的代码修复原因
React Hooks 规则要求:Hook 只能在组件顶层调用,不能在回调函数、条件语句或循环中调用。
原代码在
setTimeout回调中调用了useEngine(),违反了此规则。新方案使用 React 的状态和副作用系统:
useEffect检测到引擎类型与待恢复历史的目标类型匹配时