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.

Deconstruct props doesn't remove children

See original GitHub issue

Hi,

I found a bug when you deconstruct props, children are not deleted properly.

Here an example: https://codesandbox.io/s/k13proo6ko

in my case it generates a RangeError: Maximum call stack size exceeded.

const MyDiv = ({ children, ...rest }) => {
  console.log(rest);
  return (
    <div {...rest}>
      <div {...rest}>{children}</div>
    </div>
  );
};

Here the rest object still contains the children field. Maybe _objectWithoutPropertiesLoose is not interpreted correctly.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Kanayecommented, Apr 25, 2019

No, the property is removed properly. console.log is lazy and prints the objects state after preacts h function modified it. You can observe this behavior by logging rest.children which eveluates to undefined instead of rest example.

2reactions
marvinhagemeistercommented, Apr 25, 2019

@Kanaye is right. The issue is caused by us mutating props directly. Looks like we need to clone props in createElement/h.

@jeremycare nah, that’s still an issue and unexpected behaviour. We should fix that 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How i can destructuring {this.props.children}? - Stack Overflow
Try though first removing propTypes temporarily to see if the linting error via this destructuring assignment is resolved. If you continue to ...
Read more >
Destructuring of Props in ReactJS - GeeksforGeeks
Destructuring is a characteristic of JavaScript, It is used to take out sections of data from an array or objects, We can assign...
Read more >
Take `children` off `props` · Issue #4694 · facebook/react
Having children on props means that the props object saved in the ReactElement can't be hoisted up by an intelligent runtime, which would ......
Read more >
Learn the basics of destructuring props in React
The downside to destructuring in class components is that you'll end up destructuring the same props each time you use it in a...
Read more >
Using ES6 To Destructure Deeply Nested Objects in ... - ITNEXT
The pattern is starting to make sense when deconstructed object by object. One JS Object Within Three More Objects. So, for an even...
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