Reputation: 33
I'm building an app using react , I have a page where all images display dynamically. I want those images to open in react-modal when I click . How do i set the modal for the images to be displayed
What property should I set in a modal so that it applies to all images
Upvotes: 2
Views: 3326
Reputation: 1908
class ImageModal extends React.Component {
constructor(props) {
super(props);
this.state = {
showModal: false
};
}
setModalState(showModal) {
this.setState({
showModal: showModal
});
}
render() {
return (
<div>
<img src={ this.props.src } onClick={ this.setModalState.bind(this, true) } />
<ReactModal isOpen={ this.state.showModal }>
<img src={ this.props.src } onClick={ this.setModalState.bind(this, false) } />
</ReactModal>
</div>
)
}
Upvotes: 2