React PropTypes: range of numbers

前端 未结 4 1289
自闭症患者
自闭症患者 2021-02-14 21:56

Is there a better way to validate if a number is inside a range?

Avoiding to write

PropTypes.oneOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 
         


        
4条回答
  •  攒了一身酷
    2021-02-14 22:59

    You could use airbnb's extension to proptypes which support the range PropType

    range: provide a min, and a max, and the prop must be an integer in the range [min, max) foo: range(-1, 2)

提交回复
热议问题