Skip to content

kamicane/ow-prop-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ow-prop-type

React prop-types validation with 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 has only very basic validation, and it is super verbose to add custom validators.

Example

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)
    }
  }
}

About

React prop-types validation with ow

Resources

Stars

Watchers

Forks

Packages

No packages published