question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mssing default props

See original GitHub issue

It 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. Before Screenshot from 2019-08-26 11-13-49 After Screenshot from 2019-08-26 11-05-43

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:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
redallencommented, Oct 1, 2019

@karelhala I’m thinking that this can be a part of our greater move to using tsc instead of babel 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.

0reactions
stale[bot]commented, Dec 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found