https://github.com/kamicane/ow-prop-type
React prop-types validation with ow
https://github.com/kamicane/ow-prop-type
Last synced: 5 months ago
JSON representation
React prop-types validation with ow
- Host: GitHub
- URL: https://github.com/kamicane/ow-prop-type
- Owner: kamicane
- Created: 2020-01-08T14:07:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-08T14:09:01.000Z (over 6 years ago)
- Last Synced: 2025-10-06T03:31:08.888Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ow-prop-type
React prop-types validation with [ow](https://github.com/sindresorhus/ow)
1. when `process.env.NODE_ENV` is `'production'` it will be a shim function
2. it exports the `ow` object (or shim in `'production'`) as a property
3. will return the unprocessed `ArgumentError`
## Why
[prop-types](https://github.com/facebook/prop-types) has only very basic validation, and it is super verbose to add custom validators.
## Example
```js
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)
}
}
}
```