Skip to content

Instantly share code, notes, and snippets.

@choonkending
Created November 23, 2016 03:44
Show Gist options
  • Save choonkending/6493ee32850b536e3a871e97f39d1f59 to your computer and use it in GitHub Desktop.
Save choonkending/6493ee32850b536e3a871e97f39d1f59 to your computer and use it in GitHub Desktop.
const createEventHandlers = (el = document, eventName, handler) => ({
add: () => { el.addEventListener(eventName, handler); },
remove: () => { el.removeEventListener(eventName, handler); }
});
/*
* In component
*/
constructor(props) {
super(props);
this.handlers = createEventHandlers(document, 'click', this.props.onClose);
}
render() {
this.props.isOpen ? this.handlers.add(); this.handlers.remove();
return <div />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment