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.

{...props} causes TypeError

See original GitHub issue

This code crashes due to children being assigned to the <div>. I think it works in React. I’m assuming React doesn’t pass children when it’s empty. Not sure though.

TypeError: Attempted to assign to readonly property.

TypeError: undefined is not an object (evaluating 'e.childNodes')


Broken Code

export default ({...props}) =>
	<div {...props}>Example!</div>

Working Code

export default ({children, ...props}) =>
	<div {...props}>Example!</div>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
lukeedcommented, Feb 15, 2017

In Inferno & Preact, children gets stripped from the props object.

1reaction
tunnckoCorecommented, Feb 18, 2017

Another interesting thing when passing children to props was that you can use such thing

var Foo = ({ name, children }) => <div>
  <h1>{ name }</h1>
  <p>{ children }</p>
</div>

var link = <a href="#">Hello World</a>
var tree = <Foo name="Charlike" children={ link } />

instead of the link inside the Foo tag

var link = <a href="#">Hello World</a>
var tree = <Foo name="Charlike">{ link }</Foo>

Kinda like the first one and found it useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React error : TypeError: props.globalChange is not a function
I am having a problem in props sending in the same component and the function is not function issue coming. So how to...
Read more >
Properties of the uninitialized this.props should not be accessed
Accessing properties of the uninitialized this.props causes a TypeError exception because this.props is always undefined in the below cases.
Read more >
TypeError Handling in React.js for Map Function | Pluralsight
Learn why this error occurs and how to fix it: Uncaught TypeError: this.props.data.map is not a function.
Read more >
Uncaught TypeError: this.props.tracks is undefined - Projects
It's caused by the fact that you're not passing props into the where TrackList is rendered in the Playlist component yet, so there...
Read more >
How to Read React Errors (fix 'Cannot read property of ...
Follow the Clues: How to Diagnose the Error · TypeError is the kind of error · Cannot read property means the code was...
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