PropTypes in functional stateless component

前端 未结 5 673
情深已故
情深已故 2020-12-24 04:01

Without using class, how do I use PropTypes in functional stateless component of react?

export const Header = (props) => (
   
hi
)
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 04:47

    It isn't different with the stateful, You can add it like:

    import PropTypes from 'prop-types';
    Header.propTypes = {
      title: PropTypes.string
    }
    

    Here is a link to prop-types npm

提交回复
热议问题