npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-json-schema-proptypes

v0.4.0

Published

Dynamically generate React propType validators based on a JSON schema

Downloads

14

Readme

React-json-schema-proptypes

Build React PropTypes using a JSON Schema with introspection support.

Usage

npm install --save react-json-schema-proptypes

import propTypeSchema from 'react-json-schema-proptypes';
import React from 'react';

...

const schema = {
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    }
  }
};

class Article extends React.Component {
  static propTypes = propTypeSchema(schema)

  render() {
    ...
  }
}

Introspection

Creating propTypes using react-json-schema-proptypes exposes the schema object on the component. To get the schema, you can use the exported getComponentSchema function.

Composing schemas from child components

import propTypeSchema, {getComponentSchema} from 'react-json-schema-proptypes';
import Image from 'components/image';
import Comment from 'components/comment';
import React from 'react';

...

class Article extends React.Component {
  static propTypes = propTypeSchema({
    "type": "object",
    "properties": {
      "image": getComponentSchema(Image), // Note: Things you compose must have been curated with react-json-schema-proptypes
      "comments": {
        "type": "array",
        "items": getComponentSchema(Comment)
      }
    }
  })

  render() {
    ...
  }
}

You can also update an existing schema by passing in objects that will override* it

import propTypeSchema from 'react-json-schema-proptypes';
import BaseArticle from '../components/base-article';
import React from 'react';

...

class Article extends React.Component {
  static propTypes = propTypeSchema(BaseArticle.propTypes, {
    "properties": {
      "newProperty": { "type": "string" }
    }
  }) // Note: extending things in this way requires them to have also have been curated with react-json-schema-proptypes

  render() {
    ...
  }
}

* This will create a new object rather than mutating existing ones so you're safe to use it however you want.

API

import createPropTypes, {getComponentSchema, Schema, SchemaSymbol} from 'react-json-schema-proptypes';

createPropTypes(schema)

Given a JSON schema, return a React proptypes object.

getComponentSchema(Component)

Returns a component's schema from a component class.

SchemaSymbol

The Sympbol for react-json-schema-proptypes.

Schema

Schema.element

Is a schema that validates a React element. (Gives a schema represetation equivalent to React.Element)

Schema.node

Is a schema that validates a React node. (Gives a schema represetation equivalent to React.Node)

Schema.func

Is a schema that validates a function.

Caveats

Not all features of JSON-Schema are currently supported, for example cross-validation with other props, so we recommend keeping the schema simple and type-based rather than logic-based.

Contributors

License

MIT