React-modal worked great for us in React 14.
We upgraded to React 16 and are getting the following error.
invariant.js:38 Uncaught Error: Modal.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object
We use the exact sample code from GitHub and we have re-installed react-modal
. Any ideas?
app.js:
import React from 'react';
import ReactDOM from 'react-dom';
import ExampleModal from './components/example_modal.js';
ReactDOM.render(
<ExampleModal />
, document.querySelector('#publish-hook'));
example_modal.js:
import React from 'react';
import { Component} from 'react'
import ReactModal from "react-modal";
export default class ExampleModal extends Component {
constructor () {
super();
this.state = {
showModal: true
};
this.handleOpenModal = this.handleOpenModal.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
}
handleOpenModal () {
this.setState({ showModal: true });
}
handleCloseModal () {
this.setState({ showModal: false });
}
render () {
return (
<div>
<button onClick={this.handleOpenModal}>Trigger Modal</button>
{
<ReactModal
isOpen={this.state.showModal}
contentLabel="Minimal Modal Example"
>
<button onClick={this.handleCloseModal}>Close Modal</button>
</ReactModal>
}
</div>
);
}
}
const props = {};
//ReactDOM.render(<ExampleApp {...props} />, document.getElementById('main'))