refactor: Replace useMountMergeState with useMergedState #9383
refactor: Replace useMountMergeState with useMergedState #9383chenshuai2144 merged 1 commit intoant-design:masterfrom
Conversation
…nents This commit updates various components to replace the deprecated useMountMergeState hook with the new useMergedState hook from @rc-component/util. The changes enhance consistency and maintainability in state management across the codebase. Additionally, some imports have been cleaned up to remove unnecessary references to the removed useMountMergeState utility.
📝 WalkthroughWalkthrough该PR将自定义的 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @zzjiaxiang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求通过标准化状态管理钩子对代码库进行了重构。它将项目中原有的自定义 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
这是一个很棒的重构 PR,将项目内的 useMountMergeState 替换为从 @rc-component/util 导入的钩子函数。这提高了代码的一致性和可维护性。
我注意到代码中同时使用了 useMergedState 和 useControlledState。根据上游库 rc-component/util 的更新,useControlledState 是 useMergedState 新的推荐名称。为了保持一致性,我建议在整个项目中统一使用 useControlledState。我在几个文件中留下了修改建议。
| ]); | ||
|
|
||
| const [stateValue, setStateValue] = useMountMergeState< | ||
| const [stateValue, setStateValue] = useMergedState< |
There was a problem hiding this comment.
为了与上游库 @rc-component/util 的最新推荐保持一致,建议将 useMergedState 替换为 useControlledState。useControlledState 是 useMergedState 新的别名,使用新名称可以提高代码的可读性和未来维护性。同时请记得更新文件顶部的 import 语句:import { omit, useControlledState } from '@rc-component/util';
| const [stateValue, setStateValue] = useMergedState< | |
| const [stateValue, setStateValue] = useControlledState< |
| Group: typeof CheckCardGroup; | ||
| } = (props) => { | ||
| const [stateChecked, setStateChecked] = useMountMergeState<boolean>( | ||
| const [stateChecked, setStateChecked] = useMergedState<boolean>( |
There was a problem hiding this comment.
为了与上游库 @rc-component/util 的最新推荐保持一致,建议将 useMergedState 替换为 useControlledState。同时请记得更新文件顶部的 import 语句:import { useControlledState } from '@rc-component/util';
| const [stateChecked, setStateChecked] = useMergedState<boolean>( | |
| const [stateChecked, setStateChecked] = useControlledState<boolean>( |
| } = props; | ||
| const formRef = useRef<ProFormRef<any>>({} as any); | ||
| const [loading, setLoading] = useMountMergeState<boolean>(false, { | ||
| const [loading, setLoading] = useMergedState<boolean>(false, { |
| }; | ||
|
|
||
| const [collapsed, setCollapsed] = useMountMergeState( | ||
| const [collapsed, setCollapsed] = useMergedState( |
There was a problem hiding this comment.
| } | ||
| > = (props) => { | ||
| const [open, setOpen] = useMountMergeState<boolean>(props.open || false, { | ||
| const [open, setOpen] = useMergedState<boolean>(props.open || false, { |
There was a problem hiding this comment.
为了与上游库 @rc-component/util 的最新推荐保持一致,建议将 useMergedState 替换为 useControlledState。同时请记得更新文件顶部的 import 语句:import { omit, useControlledState } from '@rc-component/util';
| const [open, setOpen] = useMergedState<boolean>(props.open || false, { | |
| const [open, setOpen] = useControlledState<boolean>(props.open || false, { |
| const prefixCls = props.prefixCls ?? context.getPrefixCls('pro'); | ||
|
|
||
| const [menuLoading, setMenuLoading] = useMountMergeState(false, { | ||
| const [menuLoading, setMenuLoading] = useMergedState(false, { |
| const [openKeys, setOpenKeys] = useMountMergeState< | ||
| (string | number)[] | false | ||
| >( | ||
| const [openKeys, setOpenKeys] = useMergedState<(string | number)[] | false>( |
There was a problem hiding this comment.
为了与上游库 @rc-component/util 的最新推荐保持一致,建议将 useMergedState 替换为 useControlledState。useControlledState 是 useMergedState 新的别名,使用新名称可以提高代码的可读性和未来维护性。此文件中的其他 useMergedState(L593)也建议一并修改。同时请记得更新文件顶部的 import 语句:import { useControlledState } from '@rc-component/util';
| const [openKeys, setOpenKeys] = useMergedState<(string | number)[] | false>( | |
| const [openKeys, setOpenKeys] = useControlledState<(string | number)[] | false>( |
| * 用于存储最新的数据,这样可以在切换的时候保持数据的一致性 | ||
| */ | ||
| const [tableDataList, setTableDataList] = useMountMergeState< | ||
| const [tableDataList, setTableDataList] = useMergedState< |
There was a problem hiding this comment.
为了与上游库 @rc-component/util 的最新推荐保持一致,建议将 useMergedState 替换为 useControlledState。useControlledState 是 useMergedState 新的别名,使用新名称可以提高代码的可读性和未来维护性。此文件中的其他 useMergedState(L94, L110)也建议一并修改。同时请记得更新文件顶部的 import 语句:import { useControlledState } from '@rc-component/util';
| const [tableDataList, setTableDataList] = useMergedState< | |
| const [tableDataList, setTableDataList] = useControlledState< |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/table/useFetchData.tsx (1)
103-115: 注释内容与代码职责混淆。Line 103 的注释将
PageInfo类型定义与useMergedState钩子实现细节混在一起,降低了代码可读性。建议将注释聚焦于PageInfo类型本身,避免提及具体的钩子实现:♻️ 建议优化注释内容
/** - * 表示页面信息的类型 useMergedState 钩子的初始值和参数 + * 表示页面信息的类型 * @typedef {object} PageInfo * @property {number} current 当前页码 * @property {number} pageSize 页面大小 * @property {number} total 数据总量 - * @type {[PageInfo, React.Dispatch<React.SetStateAction<PageInfo>>]} */
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (24)
src/card/components/CheckCard/Group.tsxsrc/card/components/CheckCard/index.tsxsrc/field/components/Select/SearchSelect/index.tsxsrc/field/components/Select/index.tsxsrc/form/BaseForm/BaseForm.tsxsrc/form/BaseForm/LightWrapper/index.tsxsrc/form/components/FormItem/FormItemRender/index.tsxsrc/form/components/FormItem/Group/index.tsxsrc/form/components/Text/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/layout/ProLayout.tsxsrc/layout/components/GlobalHeader/ActionsContent.tsxsrc/layout/components/PageHeader/index.tsxsrc/layout/components/SiderMenu/BaseMenu.tsxsrc/table/Table.tsxsrc/table/TableRender.tsxsrc/table/TableSearch.tsxsrc/table/TableToolbar.tsxsrc/table/components/ListToolBar/index.tsxsrc/table/useFetchData.tsxsrc/utils/index.tsxsrc/utils/useEditableArray/index.tsxsrc/utils/useMountMergeState/index.tsvitest.config.mts
💤 Files with no reviewable changes (3)
- src/utils/index.tsx
- src/utils/useMountMergeState/index.ts
- vitest.config.mts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{tsx,jsx}: Use early returns whenever possible to make the code more readable.
Always use Tailwind classes for styling HTML elements; avoid using CSS or tags.
Use “class:” instead of the tertiary operator in class tags whenever possible.
Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.
Files:
src/form/BaseForm/LightWrapper/index.tsxsrc/layout/components/GlobalHeader/ActionsContent.tsxsrc/table/TableRender.tsxsrc/form/components/Text/index.tsxsrc/utils/useEditableArray/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/field/components/Select/index.tsxsrc/card/components/CheckCard/Group.tsxsrc/layout/ProLayout.tsxsrc/field/components/Select/SearchSelect/index.tsxsrc/table/useFetchData.tsxsrc/layout/components/PageHeader/index.tsxsrc/card/components/CheckCard/index.tsxsrc/table/Table.tsxsrc/form/BaseForm/BaseForm.tsxsrc/form/components/FormItem/Group/index.tsxsrc/table/components/ListToolBar/index.tsxsrc/table/TableToolbar.tsxsrc/layout/components/SiderMenu/BaseMenu.tsxsrc/form/components/FormItem/FormItemRender/index.tsxsrc/table/TableSearch.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/AGENTS.md)
**/*.{ts,tsx}: Use TypeScript and React for development
Use early returns to improve code readability
Use camelCase for property names
Props naming: Usedefault+PropNamefor initialization properties
Props naming: UseforceRenderfor forced rendering
Props naming: Useforce+SubComponentName+Renderfor sub-component forced rendering
Props naming: UseSubComponentName+Renderfor sub-component rendering
Props naming: UsedataSourcefor data sources
Props naming: Useopeninstead ofvisiblefor panel opening state
Props naming: Useshow+PropNamefor display-related properties
Props naming: UsePropName+ablefor functional properties
Props naming: Usedisabledfor disabled state
Props naming: Useextrafor additional content
Props naming: Useiconfor icons
Props naming: Usetriggerfor triggers
Props naming: UseclassNamefor class names
Event naming: Useon+EventNamefor triggering events
Event naming: Useon+SubComponentName+EventNamefor sub-component events
Event naming: Usebefore+EventNamefor pre-action events
Event naming: Useafter+EventNamefor post-action events
Event naming: Useon+EventName+Completefor continuous action completion
All components and functions must provide accurate type definitions
Avoid usinganytype, define types as precisely as possible
Use interface rather than type alias for defining object structures
Strictly follow TypeScript type design principles to ensure type safety
Ensure compilation without any type errors or warnings
Component props should be defined using interface for extensibility
Component props interface naming should followComponentNamePropsconvention
Define specialized interfaces for component state, such asComponentNameState
Complex data structures should be split into multiple interface definitions
All callback function types should explicitly define parameters and return values
Appropriately use generics to enhance t...
Files:
src/form/BaseForm/LightWrapper/index.tsxsrc/layout/components/GlobalHeader/ActionsContent.tsxsrc/table/TableRender.tsxsrc/form/components/Text/index.tsxsrc/utils/useEditableArray/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/field/components/Select/index.tsxsrc/card/components/CheckCard/Group.tsxsrc/layout/ProLayout.tsxsrc/field/components/Select/SearchSelect/index.tsxsrc/table/useFetchData.tsxsrc/layout/components/PageHeader/index.tsxsrc/card/components/CheckCard/index.tsxsrc/table/Table.tsxsrc/form/BaseForm/BaseForm.tsxsrc/form/components/FormItem/Group/index.tsxsrc/table/components/ListToolBar/index.tsxsrc/table/TableToolbar.tsxsrc/layout/components/SiderMenu/BaseMenu.tsxsrc/form/components/FormItem/FormItemRender/index.tsxsrc/table/TableSearch.tsx
**/*index.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/AGENTS.md)
Export all public interface types for user convenience
Files:
src/form/BaseForm/LightWrapper/index.tsxsrc/form/components/Text/index.tsxsrc/utils/useEditableArray/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/field/components/Select/index.tsxsrc/field/components/Select/SearchSelect/index.tsxsrc/layout/components/PageHeader/index.tsxsrc/card/components/CheckCard/index.tsxsrc/form/components/FormItem/Group/index.tsxsrc/table/components/ListToolBar/index.tsxsrc/form/components/FormItem/FormItemRender/index.tsx
**/*.{tsx,ts}
📄 CodeRabbit inference engine (.cursor/rules/AGENTS.md)
All components must support dark mode
Files:
src/form/BaseForm/LightWrapper/index.tsxsrc/layout/components/GlobalHeader/ActionsContent.tsxsrc/table/TableRender.tsxsrc/form/components/Text/index.tsxsrc/utils/useEditableArray/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/field/components/Select/index.tsxsrc/card/components/CheckCard/Group.tsxsrc/layout/ProLayout.tsxsrc/field/components/Select/SearchSelect/index.tsxsrc/table/useFetchData.tsxsrc/layout/components/PageHeader/index.tsxsrc/card/components/CheckCard/index.tsxsrc/table/Table.tsxsrc/form/BaseForm/BaseForm.tsxsrc/form/components/FormItem/Group/index.tsxsrc/table/components/ListToolBar/index.tsxsrc/table/TableToolbar.tsxsrc/layout/components/SiderMenu/BaseMenu.tsxsrc/form/components/FormItem/FormItemRender/index.tsxsrc/table/TableSearch.tsx
🧠 Learnings (25)
📓 Common learnings
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Use functional components and hooks, avoid class components
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/demo/**/*.tsx : Use functional components and hooks in demos
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Use `useLocale` hook from `components/locale/index.tsx` to get localization configuration from global context
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Support React 16 ~ 19 compatibility
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Props naming: Use `open` instead of `visible` for panel opening state
Applied to files:
src/form/BaseForm/LightWrapper/index.tsxsrc/form/components/Text/index.tsxsrc/layout/components/SiderMenu/BaseMenu.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Use functional components and hooks, avoid class components
Applied to files:
src/form/BaseForm/LightWrapper/index.tsxsrc/form/components/Text/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/card/components/CheckCard/Group.tsxsrc/table/useFetchData.tsxsrc/card/components/CheckCard/index.tsxsrc/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/demo/**/*.tsx : Use functional components and hooks in demos
Applied to files:
src/form/BaseForm/LightWrapper/index.tsxsrc/form/components/Text/index.tsxsrc/utils/useEditableArray/index.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/card/components/CheckCard/Group.tsxsrc/layout/ProLayout.tsxsrc/table/useFetchData.tsxsrc/card/components/CheckCard/index.tsxsrc/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Components should display well at different screen sizes
Applied to files:
src/layout/components/GlobalHeader/ActionsContent.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/layout/components/PageHeader/index.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Support React 16 ~ 19 compatibility
Applied to files:
src/layout/components/GlobalHeader/ActionsContent.tsxsrc/form/layouts/QueryFilter/index.tsxsrc/field/components/Select/index.tsxsrc/card/components/CheckCard/Group.tsxsrc/table/useFetchData.tsxsrc/layout/components/PageHeader/index.tsxsrc/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Props naming: Use `force` + `SubComponentName` + `Render` for sub-component forced rendering
Applied to files:
src/table/TableRender.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Props naming: Use `dataSource` for data sources
Applied to files:
src/table/TableRender.tsxsrc/table/useFetchData.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Support theme customization through ConfigProvider
Applied to files:
src/table/TableRender.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Use `useLocale` hook from `components/locale/index.tsx` to get localization configuration from global context
Applied to files:
src/form/components/Text/index.tsxsrc/field/components/Select/index.tsxsrc/layout/ProLayout.tsxsrc/card/components/CheckCard/index.tsxsrc/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Define specialized interfaces for component state, such as `ComponentNameState`
Applied to files:
src/form/components/Text/index.tsxsrc/field/components/Select/index.tsxsrc/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Appropriately use React.memo, useMemo, and useCallback for performance optimization
Applied to files:
src/utils/useEditableArray/index.tsxsrc/field/components/Select/index.tsxsrc/layout/ProLayout.tsxsrc/table/useFetchData.tsxsrc/table/Table.tsxsrc/form/BaseForm/BaseForm.tsxsrc/table/TableToolbar.tsxsrc/table/TableSearch.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Appropriately use React.memo, useMemo, and useCallback for performance
Applied to files:
src/utils/useEditableArray/index.tsxsrc/field/components/Select/index.tsxsrc/table/useFetchData.tsxsrc/table/Table.tsxsrc/form/BaseForm/BaseForm.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/demo/**/*.tsx : Use `useMemo`/`useCallback` appropriately for performance optimization in demos
Applied to files:
src/utils/useEditableArray/index.tsxsrc/field/components/Select/index.tsxsrc/table/useFetchData.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Use rc-motion for complex animations
Applied to files:
src/form/layouts/QueryFilter/index.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Use literal union types to define limited option sets
Applied to files:
src/field/components/Select/index.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Avoid using `enum`, prefer union types and `as const` instead
Applied to files:
src/field/components/Select/index.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*style*.{ts,tsx} : Use Ant Design's design token system in component styles
Applied to files:
src/card/components/CheckCard/Group.tsxsrc/layout/components/PageHeader/index.tsxsrc/layout/components/SiderMenu/BaseMenu.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Component props should be defined using interface for extensibility
Applied to files:
src/field/components/Select/SearchSelect/index.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Component ref types should be explicitly defined using `React.ForwardRefRenderFunction`
Applied to files:
src/table/useFetchData.tsxsrc/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Props naming: Use `icon` for icons
Applied to files:
src/layout/components/PageHeader/index.tsxsrc/layout/components/SiderMenu/BaseMenu.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Components should provide a `ref` attribute with structure including `nativeElement`, `focus`, and other functions
Applied to files:
src/table/Table.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{ts,tsx} : Appropriately use generics to enhance type flexibility
Applied to files:
src/form/components/FormItem/FormItemRender/index.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/demo/**/*.tsx : Demo import order: React → Dependencies → Component Library → Custom Components → Types → Styles
Applied to files:
src/table/TableSearch.tsx
📚 Learning: 2025-12-26T06:32:24.230Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/AGENTS.md:0-0
Timestamp: 2025-12-26T06:32:24.230Z
Learning: Applies to **/*.{tsx} : Use complete names rather than abbreviations in Antd naming
Applied to files:
src/table/TableSearch.tsx
🧬 Code graph analysis (2)
src/table/TableRender.tsx (1)
src/utils/useEditableArray/index.tsx (1)
recordKeyToString(44-47)
src/table/Table.tsx (1)
src/table/typing.ts (1)
FilterValue(79-79)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (javascript)
🔇 Additional comments (40)
src/form/components/Text/index.tsx (2)
52-55: LGTM!
useMergedState的使用方式正确,保持了受控/非受控状态的兼容性。初始值、value 和 onChange 的配置都符合预期。
1-1: 导入语句正确且兼容。@rc-component/util@1.7.0 正确导出 useMergedState,该钩子已在多个文件中成功使用(包括 src/utils/useEditableMap、src/utils/useEditableArray 和 src/table/useFetchData),无需进一步验证。src/layout/components/PageHeader/index.tsx (1)
2-2: LGTM!导入语句整理得当,将
ResizeObserver的导入移至顶部统一管理,消除了重复导入。这是良好的代码组织实践。src/layout/components/GlobalHeader/ActionsContent.tsx (1)
1-2: LGTM!导入语句重组合理,与 PageHeader 的重构保持一致。将
ResizeObserver导入统一到顶部,提升了代码可维护性。src/card/components/CheckCard/index.tsx (2)
1-1: 导入语句更新正确与
src/form/components/Text/index.tsx中的更改一致,使用@rc-component/util的useMergedState替代原有钩子。请参考前述文件的验证建议,确保库版本兼容性。
172-178: LGTM!
useMergedState在 CheckCard 组件中的使用正确,支持受控(checked)和非受控(defaultChecked)两种模式。状态管理逻辑与原实现保持一致。src/form/BaseForm/BaseForm.tsx (2)
1-8: LGTM!
useMergedState已正确添加到@rc-component/util的导入列表中,与该文件现有的其他工具函数导入保持一致。
671-674: LGTM!表单加载状态的
useMergedState使用正确。默认值为false,并通过propsLoading支持受控模式,onLoadingChange回调配置合理,确保了提交按钮加载状态的正确管理。src/form/BaseForm/LightWrapper/index.tsx (2)
4-4: 导入变更正确。正确添加了
useState到 React 导入列表中,以支持下方的状态管理变更。
74-74: 状态管理简化合理。将
open状态从useMountMergeState迁移到标准的useState(false)是合适的。该状态为纯本地 UI 状态,用于控制下拉框的显示/隐藏,不需要受控/非受控模式的支持,使用useState更简洁明了。src/table/TableRender.tsx (4)
13-13: 导入清理正确。移除了未使用的
Key类型导入,保持代码整洁。
18-18: 导入格式调整。将多行类型导入合并为单行,格式更简洁。这是纯格式化变更,无功能影响。
63-66: 格式化调整。对
recordKeyToString调用进行了换行格式调整,提高可读性。功能保持不变。
260-262: 条件表达式格式化。将
notNeedCardDom条件判断拆分为多行,提高代码可读性。逻辑保持不变。src/form/layouts/QueryFilter/index.tsx (4)
1-2: 依赖导入正确。正确添加了
RcResizeObserver和useMergedState的导入,以支持组件的状态管理重构。
8-8: React hooks 导入更新。添加了
useState到 React 导入列表中,用于下方的 width 状态管理。
10-10: 工具函数导入调整。移除了
useMountMergeState导入,保留了isBrowser工具函数的导入。符合本次重构的目标。
532-534: width 状态管理简化合理。将
width状态从useMountMergeState迁移到useState是正确的。该状态为组件内部响应式布局计算使用的纯本地状态,通过RcResizeObserver的回调更新(line 580),不需要受控/非受控模式支持。初始值逻辑保持不变。src/layout/components/SiderMenu/BaseMenu.tsx (5)
2-2: 正确引入新的状态管理 hook。添加了
useMergedState从@rc-component/util的导入,用于替代项目本地的useMountMergeState。
10-10: 工具导入清理。移除了
useMountMergeState导入,保留了isImg和isUrl工具函数。符合迁移目标。
575-575: 本地状态简化正确。
defaultOpenAll是纯内部状态,用于跟踪菜单默认展开行为,使用useState替代useMountMergeState是合适的简化。
577-591: openKeys 受控/非受控模式处理正确。使用
useMergedState管理openKeys状态是正确的,因为它需要支持受控和非受控模式:
- 初始值逻辑正确处理了
menu?.defaultOpenAll和propsOpenKeys === false的情况value选项正确地将propsOpenKeys === false转换为undefined以支持非受控模式onChange正确绑定到onOpenChange回调这种实现保持了组件的灵活性和向后兼容性。
593-605: selectedKeys 受控/非受控模式处理正确。使用
useMergedState管理selectedKeys状态是合适的:
- 初始值设为空数组
[]- 正确绑定
propsSelectedKeys作为受控值onChange回调正确包装了onSelect,仅在onSelect存在时才调用这种实现既支持受控模式(通过
selectedKeysprop),也支持非受控模式,并保持了 API 的向后兼容性。src/field/components/Select/SearchSelect/index.tsx (1)
31-34: 接口声明格式化调整。将
SearchSelectProps接口的extends子句从单行拆分为多行格式,提高代码可读性。这是纯格式化变更,接口定义的语义和功能保持完全不变。src/layout/ProLayout.tsx (1)
1-1: LGTM! 状态管理钩子迁移正确。从
useMountMergeState迁移到useMergedState的改动正确,两个钩子的 API 兼容,状态管理逻辑保持不变。menuLoading状态通过menu?.loading进行受控,通过menu?.onLoadingChange处理变更回调。Also applies to: 19-19, 447-450
src/form/components/FormItem/FormItemRender/index.tsx (1)
57-58: LGTM! 类型参数格式调整。这是一个纯格式化改动,将较长的泛型约束拆分为两行以提高可读性。类型定义本身没有变化,不影响运行时行为。
src/field/components/Select/index.tsx (1)
1-1: LGTM! 状态管理钩子迁移符合预期。从
useMountMergeState迁移到useControlledState的改动正确。新的 API 使用初始值工厂函数和受控值参数,符合受控/非受控模式。defaultOptions作为受控值传入,初始值根据props.valueEnum动态计算。逻辑行为保持一致。Also applies to: 271-274
src/table/components/ListToolBar/index.tsx (1)
1-1: LGTM! 导入语句整理。将
ResizeObserver的导入移至文件顶部,整合重复的导入声明。这是良好的代码组织实践,没有功能变更。src/table/TableSearch.tsx (1)
4-4: LGTM! 导入顺序调整。类型导入的顺序调整,没有运行时行为变更。这是代码组织层面的优化。
src/utils/useEditableArray/index.tsx (2)
399-399: LGTM - 简化布尔状态的正确做法将简单的布尔型 loading 状态从
useMountMergeState迁移到useState是合理的简化。对于不需要受控/合并逻辑的简单标志位,useState更加直接和高效。
517-517: LGTM - 与 SaveEditableAction 保持一致与 Line 399 的变更保持一致,将 loading 状态简化为
useState。src/card/components/CheckCard/Group.tsx (1)
320-325: LGTM - 标准的 useMergedState 迁移从
useMountMergeState到useMergedState的迁移正确,配置项(value、onChange)都已妥善处理,保持了受控/非受控模式的兼容性。src/table/Table.tsx (3)
233-240: LGTM - useControlledState 迁移正确
selectedRowKeys使用useControlledState进行受控/非受控状态管理是正确的。配合 Line 562-567 的onChange手动处理,逻辑完整。
242-251: LGTM - 惰性初始化逻辑清晰
formSearch使用useState配合初始化函数,正确处理了手动请求模式和搜索禁用的场景。
278-281: 州筛选/排序状态的动态列行为是设计的,不存在缺陷
proFilter和proSort使用useState初始化,在propsColumns变化时不会自动更新。这是有意的设计:
- 当列动态变更时,保留用户已设置的筛选/排序状态
- 针对已删除列的孤立筛选值通过
parseProFilteredValue安全处理(返回 undefined)- 用户可通过
resetAll()显式重置筛选/排序状态无需添加
useEffect来同步新的默认值。src/form/components/FormItem/Group/index.tsx (1)
36-42: LGTM - 折叠状态的标准迁移
collapsed状态正确迁移到useMergedState,使用初始化函数提供默认值,并通过props.collapsed和props.onCollapse支持受控模式。src/table/useFetchData.tsx (4)
1-2: LGTM!导入更新正确支持状态钩子迁移。导入语句已正确更新以支持从
useMountMergeState到useMergedState和useState的迁移。
94-100: 状态迁移一致且正确。
tableLoading的状态迁移与tableDataList保持一致,正确保留了复杂的 value 计算逻辑(处理 object/boolean 类型的 loading)。
131-131: 正确简化为 useState。
pollingLoading是纯内部状态,不需要外部控制或回调,使用useState替代useMountMergeState是恰当的简化,符合"选择最简单适用的钩子"原则。
84-89:useMergedStateAPI 兼容性验证完成。代码变更正确无误。根据
@rc-component/util@1.7.0官方 API 文档确认:
useMergedState的 API 签名与代码使用完全兼容- 初始值处理:
defaultData作为defaultStateValue参数正确传递- 受控/非受控行为:
value和onChange选项遵循标准 RC 组件库模式,行为与原useMountMergeState一致- React 16-19 兼容性:
@rc-component/util原生支持 React 16-19此次状态管理迁移无需进一步调整。
about
同时删除了 项目里面的
useMountMergeState改为统一从@rc-component/util导入Summary by CodeRabbit
重构
✏️ Tip: You can customize this high-level summary in your review settings.