Created
December 5, 2017 06:01
-
-
Save sumit-gupta91/b758443db900b16dc0cba78db0afb74a to your computer and use it in GitHub Desktop.
How a parent component can reuse two dropdown components
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 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