I have a component that normally requires a close method prop, so the interface would be as seen below:
interface Props {
onClose: () => void;
footer?: React.ReactElement
}
However when the footer prop is added the onClose should no longer be required. Currently I have to do the following to work around this.
<Modal
footer={renderFooterWhichHasItsOwnCloseMethod()}
onClose={null}
>
{children}
</Modal>
Is there a way to handle this with Typescript.
What I have done:
I googled and looked at some examples of but was not able to make it work. Below is one out of two results I found.
https://www.benmvp.com/blog/conditional-react-props-typescript/