Skip to content

Fix 5034 by converting Form to functional component#5043

Draft
heath-freenome wants to merge 3 commits intomainfrom
fix-5034
Draft

Fix 5034 by converting Form to functional component#5043
heath-freenome wants to merge 3 commits intomainfrom
fix-5034

Conversation

@heath-freenome
Copy link
Copy Markdown
Member

Reasons for making this change

  • Refactored Form into a functional component, moving a bunch of computations into helper function in formUtils.ts
  • Updated core/index.ts to update exports of new Form related types
  • Updated withTheme.ts to use new FormRef type
  • Updated tests for Form, NumberField and withTheme to use the new FormRef type
  • Added unit tests for all functions in formUtils

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

- Refactored `Form` into a functional component, moving a bunch of computations into helper function in `formUtils.ts`
- Updated `core/index.ts` to update exports of new `Form` related types
- Updated `withTheme.ts` to use new `FormRef` type
- Updated tests for `Form`, `NumberField` and `withTheme` to use the new `FormRef` type
- Added unit tests for all functions in `formUtils`
@heath-freenome heath-freenome marked this pull request as draft April 23, 2026 16:25
/** Backward-compatible type alias for `FormRef`. Consumers who previously used the class-based
* `Form` as a ref type (e.g. `createRef<Form>()`) can continue to do so via this alias.
*/
FormRef as Form,
Copy link
Copy Markdown
Member Author

@heath-freenome heath-freenome Apr 23, 2026

Choose a reason for hiding this comment

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

This is kind of a breaking change since the Form component being exported will cause a TS warning about using typeof Form instead. Or the user has to import type { Form } rather than import type Form. And if they need both the type and component, then they'd have to do import Form, { FormRef }

* @param next - The next render's props
* @returns - `true` when the component should skip re-rendering; `false` when it should re-render
*/
export function propsAreEqual<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this use existing util shouldRender? Slightly different since this is now a function component, but could probably be adapted instead of reimplemented


/** Always holds the latest committed state for use inside callbacks */
const stateRef = useRef(state);
stateRef.current = state;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also wrap in useLayoutEffect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe create a useLatestRef utility hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants