【问题标题】:React-modal for dynamic display of images用于动态显示图像的 React-modal
【发布时间】:2017-08-26 01:56:03
【问题描述】:

我正在使用 react 构建一个应用程序,我有一个页面可以动态显示所有图像。我希望这些图像在我单击时以反应模式打开。如何设置要显示的图像的模式

我应该在模式中设置什么属性,以便它适用于所有图像

【问题讨论】:

  • 而不是使用 创建一个新类型的组件,如

标签: reactjs react-modal


【解决方案1】:
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>
    )
}

【讨论】:

    猜你喜欢
    • 2020-07-16
    • 1970-01-01
    • 2018-06-30
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 2019-06-16
    • 2017-11-02
    相关资源
    最近更新 更多