https://github.com/nguyenchr/strummer-prop-types
Use strummer schemas as react prop types
https://github.com/nguyenchr/strummer-prop-types
proptypes react strummer validation
Last synced: about 1 month ago
JSON representation
Use strummer schemas as react prop types
- Host: GitHub
- URL: https://github.com/nguyenchr/strummer-prop-types
- Owner: nguyenchr
- Created: 2017-11-02T10:57:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-02T11:28:17.000Z (over 8 years ago)
- Last Synced: 2025-02-27T14:29:25.352Z (over 1 year ago)
- Topics: proptypes, react, strummer, validation
- Language: JavaScript
- Size: 65.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Strummer Prop Types
> Use strummer schemas as react prop types
[](https://npmjs.org/package/strummer-prop-types)
[](https://github.com/nguyenchr/strummer-prop-types)
[](https://standardjs.com)

[](https://travis-ci.org/nguyenchr/strummer-prop-types)
[](https://david-dm.org/nguyenchr/strummer-prop-types)
[](https://david-dm.org/nguyenchr/strummer-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
```js
import { Component } from 'react'
const s = require('strummer')
const sPropTypes = require('strummer-prop-types')
class MyComponent extends Component {
render () {
return (
{this.props.message}
)
}
}
MyComponent.propTypes = sPropTypes({
message: s.string()
})
export default MyComponent
```
or with a HOC
```js
import { Component } from 'react'
const s = require('strummer')
const { WithProps } = require('strummer-prop-types')
class MyComponent extends Component {
render () {
return (
{this.props.message}
)
}
}
const schema = {
message: s.string()
}
export default WithProps(MyComponent, schema)
```
## TODO
Add some tests