Skip to content

[fields] Improve useSplitFieldProps and make it public#14514

Merged
flaviendelangle merged 3 commits intomui:masterfrom
flaviendelangle:useSplitFieldInternalAndForwardedProps
Sep 11, 2024
Merged

[fields] Improve useSplitFieldProps and make it public#14514
flaviendelangle merged 3 commits intomui:masterfrom
flaviendelangle:useSplitFieldInternalAndForwardedProps

Conversation

@flaviendelangle
Copy link
Copy Markdown
Member

@flaviendelangle flaviendelangle commented Sep 6, 2024

Extracted from #14486
Closes #14515

Work

  • Improve the typing to remove the TInternalProps generic (makes the whole DX a lot lighter)
  • Turn splitFieldInternalAndForwardedProps into a hook so that the computation does not re-occur when the component has a re-render that is not caused by a prop change (it has a lot of re-renders caused by state update inside useField)
  • Move the new hook to @mui/x-date-pickers/hooks
  • Add some JSDoc

@flaviendelangle flaviendelangle self-assigned this Sep 6, 2024
@flaviendelangle flaviendelangle added the scope: pickers Changes related to the date/time pickers. label Sep 6, 2024
@mui-bot
Copy link
Copy Markdown

mui-bot commented Sep 6, 2024

Deploy preview: https://deploy-preview-14514--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 2135d08

@flaviendelangle flaviendelangle force-pushed the useSplitFieldInternalAndForwardedProps branch from 40bb070 to a5a6d79 Compare September 6, 2024 08:57
@flaviendelangle flaviendelangle changed the title [pickers] Improve useSplitFieldInternalAndForwardedProps and make it public [fields] Improve useSplitFieldInternalAndForwardedProps and make it public Sep 6, 2024
@flaviendelangle flaviendelangle marked this pull request as ready for review September 6, 2024 09:18
Copy link
Copy Markdown
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 👍

Comment on lines +44 to +51
export const useSplitFieldInternalAndForwardedProps = <
TValueType extends FieldValueType,
TProps extends { [key in InternalPropNames<TValueType>]?: any },
>(
props: TProps,
valueType: TValueType,
) => {
return React.useMemo(() => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome improvements (typing and memoization)! 💙 💯 🙌

Comment thread packages/x-date-pickers/src/hooks/useSplitFieldInternalAndForwardedProps.ts Outdated
@flaviendelangle flaviendelangle changed the title [fields] Improve useSplitFieldInternalAndForwardedProps and make it public [fields] Improve useSplitFieldProps and make it public Sep 11, 2024
@flaviendelangle flaviendelangle merged commit 309106d into mui:master Sep 11, 2024
@flaviendelangle flaviendelangle deleted the useSplitFieldInternalAndForwardedProps branch September 11, 2024 10:29
@LukasTy LukasTy mentioned this pull request Sep 12, 2024
arthurbalduini pushed a commit to arthurbalduini/mui-x that referenced this pull request Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: pickers Changes related to the date/time pickers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fields] Make splitFieldInternalAndForwardedProps public

3 participants