React PropTypes: range of numbers

前端 未结 4 2155
深忆病人
深忆病人 2021-02-14 22:31

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:44

    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)

提交回复
热议问题