2

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

Mitali
  • 33
  • 1
  • 8

1 Answers1

2
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>
    )
}
Brian
  • 1,860
  • 1
  • 9
  • 14