I have problem with react-modal. I have list of SingleElement and after click it should appear modal window with more details of clicked element. JSON with data is stored as state and from the inside of Modal I can't find way to get desired element.
Here's the modal inside render() function:
<Modal
isOpen={this.state.modalIsOpen}
onAfterOpen={this.afterOpenModal}
onRequestClose={this.closeModal}
chosenBeer={this.state.chosenBeer}
>
<h2> == Dynamically changing title of element == </h2>
<button onClick={this.closeModal}>X</button>
<img src="{ == Dynamically changing image == }" />
</Modal>
<div id="splashElements">
{
this.state.elements &&
this.state.elements.map((item, index) => {
return(<SingleElement key={index} name={item.name} href={item.href} image={item.image_url} tagline={item.tagline} onDelete={id => this.onDelete(index)} openModal={elementId => this.openModal(index)}/>)
})
}
</div>
And here are methods responsible for showing/hiding modal window:
openModal = (beerId) => {
this.setState({modalIsOpen: true, chosenBeer: this.state.beers[beerId]});
}
afterOpenModal = () =>{
// references are now sync'd and can be accessed.
}
closeModal = () => {
this.setState({modalIsOpen: false});
}