How can I declare a PropType corresponding to a nullable number?

后端 未结 4 670
时光取名叫无心
时光取名叫无心 2021-02-02 05:26

I\'m looking for a PropType that means

\"this is required, and it will either be a number or be null\"

In other words,

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 05:35

    Just use:

    PropTypes.number
    

    By default all prop types aren't required (i.e. allow null or undefined) unless you pop a .isRequired on the end of them.

    You can see the full docs for proptypes here:

    • https://reactjs.org/docs/typechecking-with-proptypes.html

提交回复
热议问题