Mssing default props
See original GitHub issueIt looks like when a lot fo components were transformed to TS a lot of them started to use default parameters instead of defaultProps.
This causes several problems
- snapshots changed when consumers used
mount
- a lot of unnecessary snapshot changes needs to be applied - React extension is not usable for lot of components - if component does not set
defaultProps
it will not display them in React extension. This might seem as a minor issue, but that is actually really usefull when you are using these components as you can change props on the fly. BeforeAfter
Even though it is correct to use default parameters instead of default props, for better code style and consistency it’s better to use default props. And of course the great benefit of helping developers to use PF4 components.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Eslint: Problem with default props in functional component ...
Eslint react plugin complain with this error ESLint: propType "gretting" is not required, but has no corresponding defaultProps declaration.
Read more >eslint-plugin-react/require-default-props.md at master - GitHub
This rule aims to ensure that any non-required prop types of a component has a corresponding defaultProps value. Note: You can provide types...
Read more >Typing defaultProps - React TypeScript Cheatsheets
The problem here is that the way GreetProps is defined, age is a required prop when it isn't because of defaultProps . ......
Read more >Default Props in React/TypeScript - DEV Community
It has to do with implementing default values for component props in ... as props , and therefore, there is no props.children to...
Read more >vue/no-required-prop-with-default
If a prop is declared with a default value, whether it is required or not, we can always skip it in actual use....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@karelhala I’m thinking that this can be a part of our greater move to using
tsc
instead ofbabel
and that we could write it as a TypeScript transform plugin. Let me explain.Currently, to generate
propTypes
, we use babel-plugin-typescript-to-proptypes which I find less than ideal. @TheRealJon and I have found numerous errors and inconsistencies in its behaviour. Our own extension can add whatever we want to the JS (propTypes
,defaultProps
, etc.) and we can enforce proper behaviour and handle function components however we want.This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.