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.

False negative of prop-types with stateless components

See original GitHub issue

When a stateless component is created as a property of an object, prop-types gives false negative:

🚫 reports “‘children’ is missing in props validation”:

Panel.Body = ({children}) => (
  <div className='Panel-body'>
    {children}
  </div>
)

Panel.Body.propTypes = {
  children: PropTypes.node
}

👌🏽 works fine:

const Body = ({children}) => (
  <div className='Panel-body'>
    {children}
  </div>
)

Body.propTypes = {
  children: PropTypes.node
}

Panel.Body = Body

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Aug 21, 2016

Another example:

🚫 reports error:

function Foo({bar}) {
  return <div>{bar}</div>
}

Foo.propTypes = {
  bar: PropTypes.string.isRequired
}

Passes:

Foo.propTypes = {
  bar: PropTypes.string.isRequired
}

function Foo({bar}) {
  return <div>{bar}</div>
}
0reactions
kentcdoddscommented, Aug 22, 2016

Cool, will do, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

False negative of prop-types with stateless components #735
When a stateless component is created as a property of an object, prop-types gives false negative: reports "'children' is missing in ...
Read more >
React: PropTypes in stateless functional component
(The instance of a PropTypes object is lowercase, but the Class/Type is uppercase. The instance is List.propTypes .
Read more >
children is missing in props validation - You.com - You.com
The rule is enforcing prop-types for all used props in your component (for documentation and debugging purpose), if you do not use the...
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for ... FUNCTIONAL COMPONENTS */ function ReactComponent(props) ...
Read more >
node_modules/eslint-plugin-react/CHANGELOG.md · master ...
no-unused-prop-types : Silence false positive on never type in TS (#2815 ... require-default-props : add option to ignore functional components (#2532 ...
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