Skip to content

Instantly share code, notes, and snippets.

@hachibeeDI
Created October 11, 2017 10:01
Show Gist options
  • Save hachibeeDI/edd71e83b16b4559146ea59172208147 to your computer and use it in GitHub Desktop.
Save hachibeeDI/edd71e83b16b4559146ea59172208147 to your computer and use it in GitHub Desktop.
Considering more readable pattern to implement modal
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