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.

`defaultProps` rule to be deprecated on function components

See original GitHub issue

defaultProps on function components is getting deprecated by React (see: https://github.com/facebook/react/pull/16210)

For this rule to follow suit, it should only be triggered when missing from class components.

The official recommendation in future versions of React is to use ES6 default values for function components.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:32
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

31reactions
KevinGhadyani-mintedcommented, Oct 7, 2019

The change isn’t to remove defaultProps from function components, but to use the official ES6 standard for defaulting props using object deconstruction and default assignment.

Where we once had:

const TestComponent.defaultProps = {
  size: 'medium',
  type: 'primary',
}

We now have:

const TestComponent = ({
  size = 'medium',
  type = 'primary',
}) => (
  // ...
)

The goal isn’t to remove defaultProps, but change how they’re defined on function components.

I would expect the defaultProps rules to function the same regardless of if I use defaultProps or object deconstruction and default assignment.

14reactions
ljharbcommented, Oct 8, 2019

Yes, it means someone would have to do the development work to add an option.

It makes sense to me to modify require-default-props so that the default is “defaultProps” for everything, but that there’s an option for function components to instead require “default arguments”, or, to ignore function components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`defaultProps` rule to be deprecated on function components
defaultProps on function components is getting deprecated by React (see: facebook/react#16210) For this rule to follow suit, it should only ...
Read more >
Stop using defaultProps - Notes and Anecdotes
And because Dan says defaultProps will be deprecated from React, which is the only reason we use them to begin with. Performance. By...
Read more >
React functional component default props vs ...
defaultProps on functional components will eventually be deprecated (as per Dan Abramov, one of the core team), so for future-proofing it's ...
Read more >
An alternative to default props for React functional components
I read recently that default props for functional components will one day be deprecated in React. It's currently possible (as of September ...
Read more >
"@hswolff @reactjs Because defaultProps on functions will ...
Because defaultProps on functions will eventually get deprecated. 11:30 PM · May 29, 2019.
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