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.

React.Children.onlyChild throws on text child

See original GitHub issue

Text child is a string so isValidComponent fails. Would it make sense for it to accept a string? Frankly I’m confused by this API…

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
eiparkcommented, Sep 13, 2016

The error message for this is: Invariant Violation: onlyChild must be passed a children with exactly one child. This led me incorrectly down the path of thinking I had passed in multiple children until I dug in and realized it was because I had a string instead of a ReactElement. Could this error message a bit more nuanced for cases such as this?

1reaction
sophiebitscommented, Sep 13, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - "React.Children.only expected to receive a single ...
It seems that <TouchableHighlight> must have exactly one child. The docs say that it supports only one child and more than one must...
Read more >
React Top-Level API
React.Children.only(children). Verifies that children has only one child (a React element) and returns it. Otherwise this method throws an error.
Read more >
A deep dive into children in React - Max Stoibers Blog
This returns the only child in this.props.children . If there is more than one child, it throws an error, thusly grinding the entire...
Read more >
React Children And Iteration Methods - Smashing Magazine
In this article, we'll discuss and learn about the use case of iterating over React `children` and the ways to do it. In...
Read more >
react children only expected receive single child
The error "React.Children.only expected to receive single React element child" occurs when we pass multiple child elements to a component that expects only ......
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