I am using Grommet and am trying to get Layer (pretty much a modal) to work when a button is pressed. I know that my onClick works because I tried a simple console.log and it works. MyModal is also able to be displayed if I use ReactDOM and render it. I think my problem has something to do with how I am calling it or returning it? I want the modal to display when the button is clicked.
MyModal.js
import React, { Component } from 'react';
import Layer from 'grommet/components/Layer';
import Header from 'grommet/components/Header';
import Heading from 'grommet/components/Heading';
import Section from 'grommet/components/Section';
import Paragraph from 'grommet/components/Paragraph';
export default class MyModal extends Component {
render () {
return (
<Layer closer={true} align="top">
<Header>
<Heading tag="h2">
Title
</Heading>
</Header>
<Section>
<Paragraph>
This is a simple dialog.
</Paragraph>
</Section>
</Layer>
);
}
};
Main.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import App from 'grommet/components/App';
import Button from 'grommet/components/Button';
import MyModal from './components/MyModal';
export default class Main extends Component {
getComponent(event) {
return <MyModal/>;
}
render () {
return (
<App centered={false}>
<Button onClick={this.getComponent.bind(this)} label="Action" />
</App>
);
}
};