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.

this.props.children and `react/prop-types` rule

See original GitHub issue

Using this.props.children triggers the rule (“‘children’ is missing in props validation”).

Shouldn’t it be an exception?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

346reactions
sebastienbarrecommented, Apr 7, 2015

All good points. [UPDATED] I think @AsaAyers is onto something, considering the Single Child section in the React doc:

With React.PropTypes.element you can specify that only a single child can be passed to a component as children.

  propTypes: {
    children: React.PropTypes.element.isRequired
  },

In other cases when this.props.children might be used (or not), this below could probably do the trick:

  propTypes: {
    children: React.PropTypes.oneOfType([
      React.PropTypes.arrayOf(React.PropTypes.node),
      React.PropTypes.node
    ])
  },
  getDefaultProps: function() {
    return {
      children: null // or [] I guess
    };
  },

111reactions
reggicommented, Sep 8, 2015

Just to clarify, children should be defined as type node, like this:

propTypes: {
  children: React.PropTypes.node
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

this.props.children and `react/prop-types` rule · Issue #7 - GitHub
With React.PropTypes.element you can specify that only a single child can be passed to a component as children. propTypes: { children: React ...
Read more >
ReactJs: What should the PropTypes be for this.props.children?
2. You probably want node. – lux · 1. Possible duplicate of only allow children of a specific type in a react component....
Read more >
Typechecking With PropTypes - React
With PropTypes.element you can specify that only a single child can be passed to a component as children. import PropTypes from 'prop-types'; class...
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >
[React] Solution for 'children' is missing in props validation ...
If you came up with this error message “ 'children' is missing in props validation eslint(react/prop-types)” , this article might help.
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