Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-jsonschema-form
Advanced tools
A simple React component capable of building HTML forms out of a JSON schema.
A simple React component capable of building HTML forms out of a JSON schema.
A live demo is hosted on gh-pages.
Requires React 0.14+.
As a npm-based project dependency:
$ npm install react-jsonschema-form --save
As a script dependency served from a CDN:
<script src="https://npmcdn.com/react-jsonschema-form@0.6.0/dist/react-jsonschema-form.js"></script>
Source maps are available at this url.
Note that the CDN version does not embed react nor react-dom.
A default, very basic CSS stylesheet is provided, though you're encouraged to build your own.
<link rel="stylesheet" href="https://npmcdn.com/react-jsonschema-form@0.6.0/dist/react-jsonschema-form.css">
import React, { Component } from "react";
import { render } from "react-dom";
import Form from "react-jsonschema-form";
const schema = {
title: "Todo Tasks",
type: "object",
required: ["title"],
properties: {
title: {type: "string", title: "Title", default: "A new task"},
done: {type: "boolean", title: "Done?", default: false}
}
};
const formData = {
title: "First task",
done: true
};
const log = (type) => console.log.bind(console, type);
render((
<Form schema={schema}
formData={formData}
onChange={log("changed")}
onSubmit={log("submitted")}
onError={log("errors")} />
), document.getElementById("app"));
That should give something like this (if you use the default stylesheet):
JSONSchema is limited for describing how a given data type should be rendered as an input component, that's why this lib introduces the concept of UI schema. A UI schema is basically an object literal describing which UI widget should be used to render a certain field
Example:
const uiSchema = {
done: {
widget: "radio" // could also be "select"
}
};
render((
<Form schema={schema}
uiSchema={uiSchema}
formData={formData} />
), document.getElementById("app"));
Here's a list of supported alternative widgets for different JSONSchema data types:
boolean
radio
: a radio button group with true
and false
as selectable values;select
: a select box with true
and false
as options;string
:textarea
: a textarea
elementinput[type=text]
element is used.$ npm start
A live development server showcasing components with hot reload enabled is available at localhost:8080.
$ npm test
$ npm run tdd
Apache 2
FAQs
A simple React component capable of building HTML forms out of a JSON schema.
The npm package react-jsonschema-form receives a total of 37,063 weekly downloads. As such, react-jsonschema-form popularity was classified as popular.
We found that react-jsonschema-form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.