0.1.0 • Published 6 years ago

json-schema-prop-types v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

JSON Schema Prop Types

JSON Schema compatibility layer for React Prop-Types.

Install

npm install json-schema-prop-types

Getting started

// TODO: Code examples

Advanced Usage

TODO: Call off to Ajv docs for advanced Schemas.

Parity with React Prop Types

This package aims to be at least equal to the props-types package in it's capability. Below is a mapping of prop-types features to this packages solution.

Prop TypeNative SupportCustom SupportNotes
anyJSON Schema blank definition
stringJSON Schema type "string"
numberJSON Scehma types "number" or "integer"
func🚫Supported by Ajv custom keyword "instanceof"
boolJSON Schema type "boolean"
oneOfJSON Schema keyword "enum"
oneOfTypeJSON Schema keyword "oneOf"
arrayJSON Schema type "array"
arrayOfJSON Schema type "array" with keyword "items"
objectJSON Schema type "object"
objectOfJSON Schema keyword "patternProperties"
instanceOf🚫Supported by Ajv custom keyword "instanceof"
shapeJSON Schema type "object" with keyword "properties"
element🚫Custom definition "_ReactElement"
node🚫Custom definition "_Node"
(...).isRequiredJSON Schema keyword "required"

Usage in production

It is recommended that you disable prop-types in production as described here: https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types

Dependencies

The Ajv JSON Schema validator powers the validation checks. This is extended by ajv-keywords in order to support validation of functions and classes.

Peer Dependencies

This package expects to be used with React, React DOM and Prop Types. The following package versions have been tested:

  • react - 16.2.0
  • react-dom - 16.2.0
  • prop-types - 15.6.0