I have a header component that contains a button, and I want this button to display another component (modal page) when clicked.
Can I do something like this:
Here is my header component:
import ComponentToDisplay from './components/ComponentToDisplay/index' class Header extends React.Component { constructor(props) { super(props) } props : { user: User } _handleInvitePlayerClick = () => { this.refs.simpleDialog.show(); } render(){ return( <Button onClick={this._handleInvitePlayerClick} ><myButton/></Button> <ComponentToDisplay /> ) } }
Here is my component for a modal page that should appear when a button is clicked on another component:
class ComponentToDisplay extends React.Component { componentDidMount() { } render() { return ( <div> <SkyLight ref="simpleDialog" title={"Title for the modal"}> {"Text inside the modal."} <Button onClick={() => this.refs.simpleDialog.hide()}>{"Close modal"}</Button> </SkyLight> </div> ) } }
The library is used for modal: https://github.com/marcio/react-skylight
javascript reactjs
Azicode
source share