npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

joi-react

1.0.1 • Public • Published

Synopsis

joi-react is a tiny wrapper to convert joi schemas into React PropType validators.

license - MIT Dependencies

NPM status

Build Status Coverage Status

Install

Node.js

With NPM

npm install joi-react

From source

git clone https://github.com/foss-haas/joi-react.git
cd joi-react
npm install
npm run test && npm run dist

API

joiToPropType(joiSchema):Function

Takes a joi schema and returns a React PropType.

Example:

var joi = require('joi');
var joiToPropType = require('joi-react');
var React = require('react');
var starsSchema = joi.number().integer().min(1).max(5).required();
var starsPropType = joiToPropType(starsSchema);
 
var Rating = React.createClass({
  displayName: 'Rating',
  propTypes: {
    stars: starsPropType
  },
  render: function () {
    var stars = [];
    for (var i = 0; i < this.props.stars; i++) {
      stars.push(React.createElement('img', {src: 'star.png'}));
    }
    return stars;
  };
});
 
React.renderToString(React.createElement(Rating));
// -> Warning: value is required
React.renderToString(React.createElement(Rating, {stars: 0}));
// -> Warning: value must be larger than or equal to 1
React.renderToString(React.createElement(Rating, {stars: 6}));
// -> Warning: value must be less than or equal to 5
React.renderToString(React.createElement(Rating, {stars: 5}));
// no warnings

License

The MIT/Expat license. For more information, see http://foss-haas.mit-license.org/ or the accompanying LICENSE file.

install

npm i joi-react

Downloadsweekly downloads

49

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability