Skip to content

Instantly share code, notes, and snippets.

@wayanjimmy
Created May 18, 2018 06:38
Show Gist options
  • Save wayanjimmy/e764002ed66abec3c340187dca2c574f to your computer and use it in GitHub Desktop.
Save wayanjimmy/e764002ed66abec3c340187dca2c574f to your computer and use it in GitHub Desktop.
React compund component
render() {
const children = React.Children.map(this.props.children, (child, index) => {
if (child.type === Panels) {
return React.cloneElement(child, {
activeIndex: this.state.activeIndex
});
} else if (child.type === List) {
return React.cloneElement(child, {
activeIndex: this.state.activeIndex,
onActivateTab: activeIndex => {
this.setState({ activeIndex });
}
});
}
return child;
});
return <Fragment>{children}</Fragment>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment