Getting started
===============
This page provides the usage instructions to get started with React Forms in
different environments. We recommend using CommonJS_ module format, but we are
also providing support for AMD and a standalone builds of React Forms.
Getting started with CommonJS
-----------------------------
React Forms is distributed as a set of CommonJS modules available through npm_
package registry. You can install both React Forms and React via ``npm`` command
line tool.
.. note::
:class: inline
``npm`` command-line utility comes bundled with a Node.js installation.
::
% npm install react-forms react
This will create a ``node_modules`` directory in the current working directory
with ``react`` and ``react-forms`` packages installed.
Now create a file called ``index.js``. First we need to bring React Forms and
React into scope using ``require()`` function. We also alias some definitions
to make them look better and more descriptive.
.. note::
:class: inline
For the sake of simplicity we will assume that all application code lives in a
single file ``index.js``. But in the real-world scenariou CommonJS module
format makes it easy to factor out application into separate modules.
::
var React = require('react')
var ReactForms = require('react-forms')
var Schema = ReactForms.schema.Schema
var Property = ReactForms.schema.Property
var Form = ReactForms.Form
The first step is to define a schema for our form. Form schemas are used to
describe what's the shape of the data form represents, how it should validate it
and how to present form fields to a user::
var schema = (