Skip to content

Instantly share code, notes, and snippets.

@sumit-gupta91
Created December 5, 2017 06:01
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 sumit-gupta91/b758443db900b16dc0cba78db0afb74a to your computer and use it in GitHub Desktop.
Save sumit-gupta91/b758443db900b16dc0cba78db0afb74a to your computer and use it in GitHub Desktop.
How a parent component can reuse two dropdown components
class ParentComponent extends Component {
state = {
active: true,
}
toggleVisibility = () =>
this.setState(({ active}) => ({
active: !active
}))
render() {
return(
<ParentComponent>
<DropDown active={active} toggleVisibility={this.toggleVisibility}/>
<DropDown active={!active} toggleVisibility={this.toggleVisibility}/>
</ParentComponent>
)
}
}
const DropDown = ({active , toggle }) => {
<div onClick={toggle}>
...some code
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment