Created
May 18, 2018 06:38
-
-
Save wayanjimmy/e764002ed66abec3c340187dca2c574f to your computer and use it in GitHub Desktop.
React compund component
This file contains hidden or 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
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