Skip to content

Instantly share code, notes, and snippets.

@Kornil
Created December 30, 2018 18:32
Show Gist options
  • Save Kornil/7c567de43a4758fa810558b107c73660 to your computer and use it in GitHub Desktop.
Save Kornil/7c567de43a4758fa810558b107c73660 to your computer and use it in GitHub Desktop.
import React, { Component, createContext } from "react";
const ModalContext = createContext({
hideModal: () => null,
show: false,
showModal: () => null
});
export default ModalContext;
export class WrapperModal extends Component {
constructor(props) {
super(props);
this.state = {
hideModal: this.hideModal,
show: false,
showModal: this.showModal
};
}
hideModal = () => {
this.setState({
show: false
});
};
showModal = () => {
this.setState({
show: true
});
};
render() {
const { children } = this.props;
return (
<ModalContext.Provider value={this.state}>
{children}
</ModalContext.Provider>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment