strummer-prop-types
v0.0.1
Published
Use strummer schemas as react prop types
Downloads
5
Readme
Strummer Prop Types
Use strummer schemas as react prop types
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