Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i have confusion about typescript in react

i am beginner to typescript,Is the following approach correct for typescript?

my parent component

interface MailDetailsProps {
  mailId?: string;
}

interface MailPopup {
  open?: boolean;
  width?: string;
  icon?: React.ReactNode;
  title?: string;
}

const MailDetails: React.FC<MailDetailsProps> = ({ mailId }) => {
  const { t } = useTranslation();
  const dispatch = useDispatch();

  const [mailPopup, setMailPopup] = useState<MailPopup>({});

  return (
    <>
      <MailDetailsPopup mailPopup={mailPopup} setMailPopup={setMailPopup} />
    </>
  );
};

MailDetails.propTypes = {
  mailId: PropTypes.string
};

export default MailDetails;

my child component

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

interface MailDetailsPopupProps {
  mailPopup: any;
  setMailPopup: React.Dispatch<React.SetStateAction<any>>;
}

const MailDetailsPopup: React.FC<MailDetailsPopupProps> = ({ mailPopup, setMailPopup }) => {
  const { t } = useTranslation();
  const [emailOpen, setEmailOpen] = useState(false);

  return (
  
  );
};

export default MailDetailsPopup;

I am not sure about define mailPopup: any.Because i already defined in my parent component.

>Solution :

First:
Don’t use …more in interface.

second:
You have mailPopup declared as any in child component so what do you expect ?
export interface and type it properly.

interface MailDetailsPopupProps {
  mailPopup: MailPopup; // exported from parent component
  setMailPopup: React.Dispatch<React.SetStateAction<MailPopup>>;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading