我的目标是在函数 (showCustomModal
) 调用(如 Modals.confirm)之后显示自定义 antd 模式。
CustomModal.tsx:
export function showCustomModal() {
return <Modal>custom modal</Modal>
}
组件.tsx
import { showCustomModal } from 'CustomModal'
const Component= () => {
const showModal = () => {
showCustomModal()
}
return <button onClick={showModal}>show modal</button>
}
答案 0 :(得分:2)
最后需要调用React组件作为回报,这里你要做的是使用状态来控制何时显示组件。
import { showCustomModal } from 'CustomModal'
const Component= () => {
const [show, setShow] = useState(false);
return (
<>
<button onClick={setShow(true)}>show modal</button>
{show && <showCustomModal />}
</>
)
}