希望这对您有所帮助.I'm trying to use reactstrap to display 2 differents modals onClick in my footer component.I managed to build a class based footer who toggle the modal visibility based on the state and an external modal element to display the modal when clicking on each 'link'.But i'm still trying to figure out a way to display a different content (title and modal body) on the same modal for each link.//FOOTERimport React, { Component } from 'react';import MainModal from '../../elements/modal';class Footer extends Component{ state = { modal: false } toggle = () => { this.setState({ modal: !this.state.modal }) } render(){ return( <footer className="container-fluid footer"> <div className="modals sm-text-center"> <span className="sm-block"><span className="fLink" onClick={this.toggle}>Terms of use</span> | <span className="fLink" onClick={this.toggle}>Privacy Policy</span></span> <div className="clearfix"/> </div> <MainModal type="basic" toggle={this.toggle} modal={this.state.modal}/> </footer> ) }}export default Footer;//MODAL TEMPLATEimport React, { Component } from 'react';import { Modal, ModalHeader, ModalBody } from 'reactstrap'; class MainModal extends Component { render(){ return( <Modal isOpen={this.props.modal} toggle={this.props.toggle}> <ModalHeader toggle={this.props.toggle}>Modal title</ModalHeader> <ModalBody> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </ModalBody> </Modal> ); } };export default MainModal;What would be the best/elegant way to display the content content for the Terms of use and the privacy policy? 解决方案 Pass "title" and body content" to toggle() method and then to <MainModal />Modal:<Modal isOpen={this.props.isModalOpen} toggle={this.props.toggle}> <ModalHeader toggle={this.props.toggle}> {this.props.modalTitle} </ModalHeader> <ModalBody>{this.props.modalBody}</ModalBody></Modal>Footer:<span className="fLink" onClick={e => this.toggle("Terms of Use", "Body for Terms of User") }> Terms of use</span><span className="fLink" onClick={e => this.toggle("Privacy Policy", "Body for Privacy Policy") }> Privacy Policy</span>State:state = { isModalOpen: false, modalTitle: "", modalBody: ""};Toggle method:toggle = (title, body) => { this.setState({ isModalOpen: !this.state.modal, modalTitle: title, modalBody: body });};Here is a complete solution: https://codesandbox.io/s/63jqmvzvnHope this helps you. 这篇关于一个组件中的React.js + Reactstrap多个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-31 18:20