-
-
Notifications
You must be signed in to change notification settings - Fork 244
refactor: Upgrade utils and replace useMergedState #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zombieJ
merged 2 commits into
react-component:master
from
EmilyyyLiu:useControlledState-use
Sep 8, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
切换到 useControlledState:导入路径与语义检查
导入路径看起来与项目现有 util 用法一致(同为 /lib/ 前缀)。请确认该导入在 CJS/ESM 打包下都可用,且
useControlledState
的受控判断与useMergedState
一致,避免受控/非受控行为改变。🌐 Web query:
💡 Result:
简短结论
为什么这么说(要点)
CJS / ESM 使用示例(推荐两种稳妥方式)
import { useMergedState } from 'rc-util'; // 或 import useMergedState from 'rc-util/es/hooks/useMergedState'(见下)
const { useMergedState } = require('rc-util');
import useMergedState from 'rc-util/es/hooks/useMergedState';
const useMergedState = require('rc-util/lib/hooks/useMergedState').default;
注意:避免直接依赖未承诺为 public API 的路径名(例如 /lib/hooks/useControlledState),因为 package 的 exports/esm 改动或重命名会导致断裂。
useControlledState vs useMergedState 行为差异(要点)
快速参考(阅读/引用)
需要我做的下一步?
使用官方导出 useMergedState 替换私有路径引用
直接引用 '
@rc-component/util/lib/hooks/useControlledState
' 属于未承诺的内部子路径,可能因 CJS/ESM 打包或后续版本变更而失效。请改为:(若必须使用子路径,可在 ESM 环境下谨慎使用:
但仍存在兼容风险)
确保返回值和受控/非受控逻辑(支持 defaultValue、value、onChange、postState,以 value 优先)与原实现保持一致。
🤖 Prompt for AI Agents