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
Remove defaultProps
and propTypes
#11612
Conversation
Not quite sure how to use ES6 syntax for styled-components like:
May not be a problem if React 19 doesn't shout about it. |
defaultProps
and propTypes
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.
One question / concern - if we were to ever convert any of these components to Typescrpt, we don't have PropTypes to tell us if fields are required or not.
We will also need to update the Migrate Legacy Component doc to remove any mention of propTypes (if we haven't already done so)
@@ -119,7 +118,11 @@ const BrandSvg = styled.svg` | |||
} | |||
`; | |||
|
|||
const LocalisedBrandName = ({ linkId, product, serviceLocalisedName }) => { | |||
const LocalisedBrandName = ({ | |||
linkId = null, |
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.
Does it matter that this is a required value (it did not have a default value before)?
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.
Which value are you referencing? linkId
had a default of null
and serviceLocalisedName
had a default of null
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.
Copypasta from Slack:
Nice! Thank you.
For the styled components issue with defaultProps, since React isn’t raising flags about their usage currently, it might be safe to leave them as is in the short term. However, for long-term maintenance and consistency, it might be worthwhile to schedule a gradual rewrite of these components into a supported pattern, possibly for when we tackle other refactoring tasks or feature upgrades.
Would it be worthwhile to add additional tests focusing on targeted components where defaultProps were replaced with default parameters to ensure there are no edge cases we're missing where the behaviour could diff?
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.
Huge respect doing this presumably without a codemod! I'm not sure if all my points are necessary, just wanted to point out semantic differences so they can be checked
Thats correct, we won't have a reference to the types that they can accept anymore. This is disadvantage of doing it this way since we have a hybrid of JS and TS. I guess refactoring components to TS will tighten up an loose types over time, but I can't think of any other ways other than something like JSDoc, which would be a huge undertaking. I will remove the Readme references. |
Thanks, that makes sense. I think we're safe to keep the Not really sure if its worth adding more tests. The current ones, along with snapshots/Chromatic should highlight regressions already, so I don't think adding more will help much? Happy to be wrong though! |
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.
Thanks for the clarifications and changes, all looks good
Overall changes
defaultProps
andpropTypes
from the codebase as these will become removed/deprecated in React 19+ https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-proptypes-and-defaultpropsdefaultProps
before (see the code example in the React docs linked above for a demonstration of this)testing-library/react-hooks
is becoming deprecatedArticle
type to replace theinferProps
version previouslyreact-test-renderer
as it will become deprecated and is not used in the codebaseCode changes
defaultProps
andpropTypes
declarations from the codebase in favour of using ES6 default valuesclassName
prop on affected componentsTesting
Helpful Links
Add Links to useful resources related to this PR if applicable.
Coding Standards
Repository use guidelines