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.

Investigate usage of 'react/require-default-props' & 'react/default-props-match-prop-types'

See original GitHub issue

Recently, the following was added to the .eslintrc.js file to warn about new linting rules.

    'react/require-default-props': ['warn'],
    'react/default-props-match-prop-types': ['warn']

It seems like these should be errors, however, more research should be done. This issue is to investigate the new rules.

If the rules should be errors, then this issue will require code changes to conform to the new lint rules.

If the rules should be turned off, then only configuration changes will be necessary.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
YimniChancommented, Jul 23, 2020

The react/require-default-props rule should be an error. If we do not set any default props, the undefined display should take place of the props that are not sent by the parent component. In execution, an undefined variable may cause the application to break if it is used and there are no safety precautions in place. We do not want that to occur. Furthermore, we should set a defaultProps value, and when a prop is missing, the defaultProps value will replace the undefined.

The react/default-props-match-prop-types rule should be turned off. In the naming convention used in code, variable names usually have the same name as its props variable, even if they are not in the same file. PropTypes exports are for validating the data type is match and valid. Look like the default-props-match-prop-types is a kind of fixed shape. It seems not necessary in this case. Furthermore, projects have interfaces that provide the benefit of type-checking values shape. The props that are passed around normally follow interface rules. Interface set or applies the requirement properties and their type. When we try to use the properties for the variable, the system just checks did the object we pass to the function meets the requirements listed. The interface can be extended and changed to fit the need of the application, Prop types of the default drop might be changing while calling by different functions.

0reactions
tehKapacommented, Jul 21, 2020
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 >
Flow does not detect default Props · Issue #6644 - GitHub
I'm using Eslint with this rules : "react/require-default-props". Which basically means : if a props is required, you have to not set ...
Read more >
A complete guide to React default props - LogRocket Blog
Cover three ways to implement default props in React and provide default values for props that are not required by the component.
Read more >
Eslint Plugin React: React-specific Linting Rules for ESLint
Enforce all defaultProps are defined and not "required" in propTypes., react/destructuring-assignment, Enforce consistent usage of destructuring assignment ...
Read more >
Default Props in React/TypeScript - DEV Community ‍ ‍
To illustrate the issue, I'm gonna take something from a plain-ol' JS component, and convert it into a TS component. The stub of...
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