Skip to content
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

Resolve Controlled Component Error by Initializing with Empty Strings #1586

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

mgold1234
Copy link
Collaborator

@mgold1234 mgold1234 commented Jan 23, 2024

This commit fixes the "A component is changing an uncontrolled input to be controlled" error in React components by ensuring input values are consistently initialized as strings. Previously, values initialized as undefined led to inconsistencies in controlled component behavior. By initializing with empty strings or using value={someValue ?? ''}, we ensure that input components remain controlled throughout their lifecycle, complying with React's expectations for controlled components and enhancing overall component stability.

@mgold1234 mgold1234 requested review from regexowl and lucasgarfield and removed request for regexowl January 23, 2024 10:32
@mgold1234 mgold1234 force-pushed the empty_default_string branch 3 times, most recently from 7306100 to 25b1ec7 Compare January 25, 2024 15:44
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
src/store/wizardSlice.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@regexowl regexowl left a comment

Choose a reason for hiding this comment

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

Looks good! Added a few comments

@mgold1234
Copy link
Collaborator Author

/retest

@lavocatt lavocatt force-pushed the empty_default_string branch from 6316d75 to fdc3772 Compare January 30, 2024 08:53
Copy link
Contributor

@lavocatt lavocatt left a comment

Choose a reason for hiding this comment

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

The commit needs a better message.
You can take the title & description of the PR and put it in there it would work fine.

@mgold1234 mgold1234 requested a review from lavocatt January 30, 2024 09:08
@mgold1234 mgold1234 force-pushed the empty_default_string branch from fdc3772 to 9011f43 Compare January 30, 2024 09:08
@mgold1234 mgold1234 force-pushed the empty_default_string branch from 9011f43 to bd14f06 Compare January 30, 2024 09:10
This commit fixes the "A component is changing an uncontrolled input to be controlled" error in React components by ensuring input values are consistently initialized as strings. Previously, values initialized as undefined led to inconsistencies in controlled component behavior. By initializing with empty strings or using value={someValue ?? ''}, we ensure that input components remain controlled throughout their lifecycle, complying with React's expectations for controlled components and enhancing overall component stability.
@mgold1234 mgold1234 force-pushed the empty_default_string branch from bd14f06 to 03a7d64 Compare January 30, 2024 09:13
Copy link
Contributor

@lavocatt lavocatt left a comment

Choose a reason for hiding this comment

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

🚀 I think that this is exactly what @lucasgarfield had in mind in the slack thread the other day. Thanks for taking care of it!

@regexowl regexowl merged commit 854d87c into osbuild:main Jan 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants