-
Notifications
You must be signed in to change notification settings - Fork 25
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
Migrate components default props usage #3027
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
dbgmd-00001.sign
Outdated
@@ -0,0 +1,6 @@ | |||
tree 0003675ccdfb583bbe7bf1a3380aefaad9ce7c12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file something that should be ignored/removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. That was a mistake.
I removed those files.
…commercetools/ui-kit into fec-138-default-props-migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builds fine, and just the class components still have defaultProps. Looks good to me 💯
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. just out of curiosity, what percentage of this was completed by the codemod?
@ByronDWall That's a good question but does not have a direct answer. The codemod refactored around 60 files. The goal is for the codemod to cover the majority of a codebase, but not getting to a 100% coverage as that would take too much effort. |
Summary
This PRs migrated the way we use
defaultProps
in React components as a preparation step to the upcoming overall migration from React v17 to React v19.We're using a codemod published from
app-kit
(reference) in order to automate the process as much as possible.Description
The way we are using React components
defaultProps
in our codebase is no longer supported in the new React 19 version (reference).This is the main concept:
NOTES
Something to bear in mind about the new pattern for using default props is that those props are not computed until the component is renderer whereas the legacy pattern make them available even before.
This has been discovered while migrating the
RadioGroup
andPrimaryActionDropdown
components where we are inspecting the received children before rendering.Here is a code example:
When using the legacy
defaultProps
property, the props of the child included thecomponents
prop as it was a default value (empty object).With the new pattern (the default value is in the component function declaration), the props of the child at this point does not include that property.