Created
October 11, 2017 10:01
-
-
Save hachibeeDI/edd71e83b16b4559146ea59172208147 to your computer and use it in GitHub Desktop.
Considering more readable pattern to implement modal
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
import {EventEmitter} from 'events'; | |
import React, {Component} from 'react'; | |
import Modal from 'components/modal'; | |
export default function WithModal (id, title, trigger) { | |
return (TargetComponent, key, descriptor) => class extends Component { | |
constructor() { | |
super(); | |
this.state = {open: false}; | |
this.trigger = new EventEmitter(); | |
this.trigger.on('open', () => this.setState({open: true})); | |
this.trigger.on('close', () => this.setState({open: false})); | |
} | |
render() { | |
return ( | |
<div> | |
<TargetComponent {...this.props} modalTrigger={this.trigger} /> | |
<Modal open={this.state.open}> | |
hogeee | |
</Modal> | |
</div> | |
); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment