Skip to content

Instantly share code, notes, and snippets.

@dandean
Created July 18, 2016 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dandean/217baf911785b3c9d52dd9050a90c1c5 to your computer and use it in GitHub Desktop.
Save dandean/217baf911785b3c9d52dd9050a90c1c5 to your computer and use it in GitHub Desktop.
Remove props...
// I haven't tested this one, but something like this should work?
class Component1 extends React.Component {
render() {
// Create a new `props` object without `foo` and `bar` properties
const {
...props,
foo,
bar
} = someComponent.props;
return React.cloneElement(someComponent, props);
}
}
class Component1 extends React.Component {
render() {
// Create a new `props` object without `foo` and `bar` properties
const {
...props,
foo,
bar
} = this.props;
// Drop just the clean props object into the component:
return <Component2 {...props} />
}
}
@tokland
Copy link

tokland commented Aug 11, 2018

The first snippet won't work: React.cloneElement(someComponent, props) merges props, so foo and bar will still be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment