Last active
January 11, 2017 04:17
-
-
Save ptgamr/a6521ddab585706de80c8cfdca4e9598 to your computer and use it in GitHub Desktop.
hoc question
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 MyComponent extends Component { | |
render() { | |
return ( | |
<div> | |
<OutsideClick> | |
<button onClick={toggleModal}>Show modal 1</button> | |
{ isModalVisible && this.renderModal(1) } | |
</OutsideClick> | |
<OutsideClick> | |
<button onClick={toggleModal}>Show modal 2</button> | |
{ isModalVisible && this.renderModal(2) } | |
</OutsideClick> | |
</div> | |
) | |
} | |
renderModal(type) { | |
// render different things based on type | |
} | |
} |
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 MyComponent extends Component { | |
render() { | |
return ( | |
<div> | |
<OutsideClick visibleState={this.state.modalVisible['1']} onOutsideClick={this.hideModal('1')} > | |
<button onClick={this.toggleModal('1')}>Show modal 1</button> | |
{ this.state.modalVisible['1'] && this.renderModal('1') } | |
</OutsideClick> | |
<OutsideClick visibleState={this.state.modalVisible['2']} onOutsideClick={this.hideModal('2')} > | |
<button onClick={this.toggleModal('2')}>Show modal 2</button> | |
{ this.state.modalVisible['2'] && this.renderModal('2') } | |
</OutsideClick> | |
</div> | |
) | |
} | |
toggleModal(id) { | |
return () => { | |
this.setState({ | |
modalVisible: { | |
...this.state.modalVisible, | |
[id]: !this.state.modalVisible[id] | |
} | |
}) | |
}; | |
} | |
hideModal(id) { | |
return () => { | |
this.setState({ | |
modalVisible: { | |
...this.state.modalVisible, | |
[id]: false | |
} | |
}); | |
}; | |
} | |
renderModal(type) { | |
// render different things based on type | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment