首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于动态显示图像的React模式

用于动态显示图像的React模式
EN

Stack Overflow用户
提问于 2017-04-01 01:42:26
回答 1查看 2.8K关注 0票数 2

我正在使用react构建一个应用程序,我有一个动态显示所有图像的页面。当我点击的时候,我希望这些图片在react-modal模式下打开。如何设置要显示的图像的模式

我应该在模式中设置什么属性才能使其应用于所有图像

EN

回答 1

Stack Overflow用户

发布于 2017-04-01 02:02:26

代码语言:javascript
复制
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>
    )
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43146697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档