| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
React prop-types validation with ow
prop-types has only very basic validation, and it is super verbose to add custom validators.
import propType, { ow } from 'ow-prop-type'
class MyComponent extends React.Component {
static propTypes = {
// propType with a predicate
total: propType(
ow
.number
.integer
.greaterThanOrEqual(0)
),
// propType with a callback, must return a predicate
current: propType((props) => {
return ow
.number
.integer
.greaterThanOrEqual(0)
.lessThanOrEqual(props.total)
}
}
}| Back | FazBrowse Home | New Git URL |