/strummer-prop-types

Use strummer schemas as react prop types

Primary LanguageJavaScript

Strummer Prop Types

Use strummer schemas as react prop types

NPM License

JavaScript Style Guide stability-experimental Build Status

Dependencies Dev dependencies

Why

  • Can share custom validators between server and client
  • Can do more complex validation out of the box (e.g. min and max length of a string)

Usage

import { Component } from 'react'
const s = require('strummer')
const sPropTypes = require('strummer-prop-types')

class MyComponent extends Component {
  render () {
    return (
      <div>{this.props.message}</div>
    )
  }
}

MyComponent.propTypes = sPropTypes({
  message: s.string()
})

export default MyComponent

or with a HOC

import { Component } from 'react'
const s = require('strummer')
const { WithProps } = require('strummer-prop-types')

class MyComponent extends Component {
  render () {
    return (
      <div>{this.props.message}</div>
    )
  }
}

const schema = {
  message: s.string()
}

export default WithProps(MyComponent, schema)

TODO

Add some tests