In your root index.js (or whatever you call it) file
// index.jsimportReactfrom'react';importReactDOMfrom'react-dom';importModalProviderfrom'react-beast-modal';importAppfrom'./App';importHomefrom'./home';/***************************************************** ** create a configuration variable ****************** *****************************************************/constmodalConfig={backdropStyle: {// defaults to empty objectbackgroundColor: 'rgba(0, 0, 0, 0.3)'},modalContainerStyle: {//default to empty objectborderRadius: '2px'},closeOnBackdropClick: true// default is false}/***************************************************** ** wrap the outermost component in the modal provider *****************************************************/ReactDOM.render(<div><ModalProviderconfiguration={modalConfig}><App><Home/></App></ModalProvider></div>,document.getElementById('root'));
In any component you want to use the modal, import the withBeastModal HOC (Higher Order Component)
// home.jsimportReactfrom'react';/* withBeastModal is a HOC that adds a function `toggleBeastModal` * and a boolean `beastModalVisible` to the props */import{withBeastModal}from'react-beast-modal';importWelcomeModalfrom'./welcomeModal';classHomeextendsReact.Component{showWelcomeModal=()=>{const{ beastModalVisible }=this.props;// toggleBeastModal takes an object with two props// isVisible (boolean): default is false// modalContent (react element):this.props.toggleBeastModal({isVisible: !beastModalVisible,modalContent: (<WelcomeModal/>)})}render(){return(<div><h1>Home Page</h1><buttononClick={this.showWelcomeModal}>Click me</button></div>);}}// pass the component to the `withBeastModal` HOCexportdefaultwithBeastModal(Home);