在一个页面中,我需要多个模态,我做到了这一点
import ApproveModal from '~/components/common/modal'
import RejectModal from '~/components/common/modal'
this.setState({ openApproveModal: true })
{openApproveModal && <ApproveModal />
this.setState({ openRejectModal: true })
{openRejectModal && <RejectModal />
不确定这是正确的方法,但我看到可能有重复的代码,如果我有3-4个动作,我需要导入4个确认模式?
发布于 2018-01-28 19:15:22
在您的modal
组件中,只需导出各种通道的多个实例:
export { ApproveModal, DeclineModal };
然后只需使用非常有用的解构模式导入它们(更多信息在这里:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment):
import { ApproveModal, DeclineModal } from '~/components/common/modal';
https://stackoverflow.com/questions/48485693
复制相似问题