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.

Putting children inside <Line> throws a React error

See original GitHub issue

Putting any children (for example, a <LabelList> inside a <Line> component, or even just

<Line ... >
<div></div>
</Line>

throws the error:

react-dom.development.js?61bb:530 Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

I’ve been looking through the code, and found a few things out:

  • If I dig around in the library code in node_modules/recharts/es6 and remove adaptEventHandlers(this.props) from line 158 inside the render method of shape/Curve, this error goes away
  • If I look inside renderByOrder in utils/ReactUtils I can’t see any special handling of children of elements to be rendered, and similarly chart/generateCategoricalChart seems to have a map of types it can render as children, but seems to have no specification for any children

The API specifically states this is how, for example, to do LabelLists (http://recharts.org/en-US/api/LabelList) and I see no other way of doing this. I’m not a typescript expert and this codebase is rather complex, so I’m not sure I’ve hit upon exactly the right cause, but I hope this gives enough info for you to reproduce? This is a small gist of the sort of thing I was working on: https://gist.github.com/James-Reed-cognito/97fd00ace04865cb101f8bc40f8c41d4

Just as an fyi - putting the children into the <Line> does work - I can put a <LabelList> inside it, and it renders, it’s just that I get this very annoying react error on the console that clogs it up and clogs up tests too.

If you need any more info please do let me know.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
xile611commented, Mar 13, 2020

Please open an issue follow the issue guide.

0reactions
James-Reed-cognitocommented, Mar 13, 2020

Hi all, I’ve opened a new issue following the guide here https://github.com/recharts/recharts/issues/2051 if you want to follow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Boundaries - React
A class component becomes an error boundary if it defines either (or both) of the lifecycle methods static getDerivedStateFromError() or componentDidCatch() .
Read more >
javascript - "React.Children.only expected to receive a single ...
Usually it happen in TochableHighlight. Anyway error mean that you must used single element inside the whatever component. Solution : You can use...
Read more >
Understanding the "Objects are not valid as a react child" Error ...
The "Objects are not valid as a React child" error happens when trying to render a collection of data by mistakenly returning the...
Read more >
React Error Handling And Reporting With Error Boundary And ...
In this article, we'll look at error boundaries in React. ... is thrown inside a component, the error boundary is the first line...
Read more >
Use react-error-boundary to handle errors in React
The problem is we need to either pass a subject prop (as a string) or default the subject prop's value. Obviously, this is...
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