0.0.1 • Published 8 years ago

strummer-prop-types v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Strummer Prop Types

Use strummer schemas as react prop types

JavaScript Style Guide stability-experimental Build Status

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