A
A
And19912018-12-22 04:56:30
React
And1991, 2018-12-22 04:56:30

Modal window in map() react js?

help me please. I don't understand how to open a modal window with elements. There is an array that generates a different number of elements in the component (from 4 to 10) and for each there should be a modal viewer window. I use map() to create the required number of elements, and then...

<div className="general">
            {this.props.filteredBooks.map((item, index) =>
            <div className="book-item" key={index}>
                <div className="size-bg" onClick={this.openModal}>
                    <img src={item.Image}/>
                </div>
                <h3>{item.Name}</h3>
                <p>{item.Author}</p>
                <div className="rating" key={index}>
                    <img src={item.ImageRating} />
                </div>
                <Modal
                    isOpen={this.state.modalIsOpen}
                    ariaHideApp={false}
                    onRequestClose={this.handleCloseModal}
                    className="Modal"
                    overlayClassName="Overlay"
                >
                    <div className="image-modal">
                        <img src={item.Image}/>
                    </div>
                    <button onClick={this.closeModal}>Закрыть модальное окно</button>
                </Modal>
            </div>

everything works as it should, but the image is always the same there, and I need to somehow change it depending on the element being pressed

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question