pradel / react-responsive-modal

Simple responsive react modal
https://react-responsive-modal.leopradel.com/
MIT License
606 stars 95 forks source link

feature: Export ModalProps #423

Closed johnoppenheimer closed 4 years ago

johnoppenheimer commented 4 years ago

Having the ModalProps exported might be useful for creating parent component that still comply with the props, without having to rewrite type for those.

hudochenkov commented 4 years ago

I just came here from changelog. It is possible to use props from a component without component needing to export its interface. This is how I use it:

import ModalLib from 'react-responsive-modal';

type ModalLibProps = React.ComponentProps<typeof ModalLib>;

interface Props {
  open: ModalLibProps['open'];
  onClose: ModalLibProps['onClose'];
  children: React.ReactNode;
  showCloseIcon?: ModalLibProps['showCloseIcon'];
  closeOnEsc?: ModalLibProps['closeOnEsc'];
  closeOnOverlayClick?: ModalLibProps['closeOnOverlayClick'];
}

https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase#props-extracting-prop-types-of-a-component