我正在使用 react 构建一个应用程序,我有一个页面,所有图像都动态显示。我希望这些图像在我单击时以反应模式打开。如何设置要显示的图像的模式
我应该在模式中设置什么属性以便它适用于所有图像
我正在使用 react 构建一个应用程序,我有一个页面,所有图像都动态显示。我希望这些图像在我单击时以反应模式打开。如何设置要显示的图像的模式
我应该在模式中设置什么属性以便它适用于所有图像
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>
)
}