8000 fix CustomChildComponent remount by scamden · Pull Request #131 · iway1/react-ts-form · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix CustomChildComponent remount #131

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

Conversation

scamden
Copy link
Collaborator
@scamden scamden commented Jul 19, 2023

Noticed that having a function as child rendered as a component was causing the whole form to rerender on some kinds of changes. Call the function as a function instead to avoid this bug. Added a test to prove the issue and fixed.

Note: this does mean our custom child has all the limitations of a normal render prop, but I think that should have already been implied. If a true component is needed it can be rendered from within the function.

@vercel
Copy link
vercel bot commented Jul 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-ts-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 19, 2023 11:13pm

=> {}}
>
{(fields) => {
const { isDirty } = useFormState();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i added this to the test and made it work, but maybe the assumption should be that it doesn't? I think hooks strictly speaking are not completely safe to use in a render prop..

renderedFields,
}: {
renderedFields: RenderedFieldMap<SchemaType>;
CustomChildrenComponent?: FunctionComponent<RenderedFieldMap<SchemaType>>;

Choose a reason for hiding this comment

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

is this really a FunctionComponent? isn't it just a function? it's a render prop not a component yeah?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh good point! That's the whole reason for this change lol :)

Copy link
@spikebrehm spikebrehm left a comment

Choose a reason for hiding this comment

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

lgtm!

@scamden
Copy link
Collaborator Author
scamden commented Jul 20, 2023

gonna go ahead and merge this since it's a bug fix

@scamden scamden merged commit 1ab3e96 into iway1:main Jul 20, 2023
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
0