Javascript 反应:通过钩子在模态组件上强制单击事件?
我们有一个现有的模态组件,它有一个触发器属性:Javascript 反应:通过钩子在模态组件上强制单击事件?,javascript,reactjs,Javascript,Reactjs,我们有一个现有的模态组件,它有一个触发器属性: <SimpleModal defaultOpen={defaultOpen} title={title} trigger={(e) => DocumentUploadButtonTrigger(e, title)} content={( ... /> )} /> 我的触发器 trigger={(e) => OpenIfInterestPaymentId(e, interestPay
<SimpleModal
defaultOpen={defaultOpen}
title={title}
trigger={(e) => DocumentUploadButtonTrigger(e, title)}
content={(
...
/>
)}
/>
我的触发器
trigger={(e) => OpenIfInterestPaymentId(e, interestPaymentId)}
触发功能
const OpenIfInterestPaymentId = (onClick: () => void, interestPaymentId: string) => {
// How can i get trigger the click event of the modal
// based on interestPaymentId has value or not ?
};
我不明白你为什么不在模态组件之外管理模态的状态。那么您就不需要在这里触发函数了。再想一想,我还建议您在这里过度考虑您的整个设置。将一个函数传递给一个函数来渲染一个组件,这感觉非常奇怪。这根本不是React的本意。您拥有接收属性的组件。无需使用返回组件的函数。组件本身实际上只是一个返回JSX的函数。只是一个想法。@Julian是的。。你可能就在那里……)我实际上在考虑创建一个新的模态组件,该组件采用真-假触发器。。我不知道以前的开发者为什么会这样做,但是。。能用现在的方式解决吗?不知道我是怎么做到的。
const [interestPaymentId, setInterestPaymentId] = useState('');
trigger={(e) => OpenIfInterestPaymentId(e, interestPaymentId)}
const OpenIfInterestPaymentId = (onClick: () => void, interestPaymentId: string) => {
// How can i get trigger the click event of the modal
// based on interestPaymentId has value or not ?
};