Created
July 18, 2016 18:18
-
-
Save dandean/217baf911785b3c9d52dd9050a90c1c5 to your computer and use it in GitHub Desktop.
Remove props...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first snippet won't work:
React.cloneElement(someComponent, props)
merges props, sofoo
andbar
will still be there.