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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-form-composer

v3.1.3

Published

Form validation and state management for react, react-native and isomorphic apps.

Readme

react-form-composer

Go to live examples, code and docs.

NPM Version NPM Downloads npm bundle size Build Status

Introduction

React-form-composer provides validation and state management for react, react-native and isomorphic forms. It has a download size of less than 7kB, is written with hooks and is optimized for fast rendering.

The small but powerful api is simular to ones provided by Informed or Redux-Form and it makes it suitable for anything from simple input forms through to large multi-row CRUD applications.

From Version 2.5 a set of ui-components is included. Version 3.0 has been simplified - now it is easier to get started.

Getting Started

Install with npm or yarn

npm install --save react-form-composer or yarn add react-form-composer

Create a Simple Form

import React from 'react';
import {
  Form,
  FormSpy,
  useForm,
  Text,
  TextArea,
  RadioGroup,
  Radio,
  Checkbox,
  Select,
  ValidationMessage
} from 'react-form-composer';

const TheFormState = () => {
  const {state} = useForm();
  return (
    <pre>
      <code>{JSON.stringify(state.fieldValues, null, 2)}</code>
    </pre>
  );
};

const isValidSelector = state => state.formStatus.isValid;
const Button = (props) => (
  <FormSpy selector={isValidSelector}>
    {(isValid) => (
      <button {...props} style={{backgroundColor: isValid? 'green': 'cyan'}} >Submit</button>
    )}
  </FormSpy>
);

const lengthAtLeast5 = value => {
  return !value || value.length < 5 ? 'Field must be at least five characters' : undefined;
}

const flexColumn = {
  display: 'flex',
  flexDirection: 'column',
  marginTop: '10px',
  maxWidth: '200px'
}

const MyForm = () => {
  return (
    <Form onSubmit={submitValues} onSubmitSuccess={clearValues}>
      <label>
        Field One (5+ chars):
        <Text name="fieldOne" required validate={lengthAtLeast5}/>
      </label>
      <ValidationMessage name="fieldOne" render={error => <p>{error}</p>}/>
      <label>Text Area: <TextArea name="fieldTwo"/></label>
      <label>Age: <Text name="age" type="number"/></label>
      <RadioGroup name="pet">
        <div><label>Dog: <Radio value="dog" selected/></label></div>
        <div><label>Cat: <Radio value="cat"/></label></div>
      </RadioGroup>
      <label>Authorize? <Checkbox name="authorize"/></label>
      <label>
        Frequency
        <Select name="frequency" required>
          <option value="" disabled>
            Select One...
          </option>
          <option value="daily">Daily</option>
          <option value="weekly">Weekly</option>
          <option value="monthly">Monthly</option>
        </Select>
      </label>
      <label>
        Exercise
        <Select name="exercice" multiple>
          <option value="Walk">walk</option>
          <option value="Run">run</option>
          <option value="Cycle">cycle</option>
          <option value="Swim">swim</option>
        </Select>
      </label>
      <Button/>
      <TheFormState/>
    </Form>
  );
};

function submitValues(values) {
  window.alert(`You submitted:${JSON.stringify(values, null, 2)}`)
}

function clearValues(form) {
  form.updateFields({});
}

export default MyForm;

Going Further

React-form-composer is written for developers. For example, the built-in ui-components (like Text, Checkbox) make no use of any special/private features - they are written using the public api provided by the Field component.

Design choices like this is what makes react-form-composer none-perscriptive - you can easily write your own ui-components or add features in many other ways.

To see this in practise take a look the CRUD example:

Create a CRUD/REST-api form (See live example)

import React from 'react';
import RestApiCrudForm from '../../data-components/rest-api-crud-form';
import {TextInput, NumberInput, Checkbox} from '../../ui-components';

const USER_ID=3;
const Todo = ({disabled=false, index}) => {
  return (
    <>
      <NumberInput
        defaultValue={USER_ID}
        disabled={true}
        name="userId"
        id={`userId${index}`}
        required
        label="userId"
      />
      <NumberInput
        disabled={true}
        name="id"
        id={`id${index}`}
        label="id"
      />
      <TextInput
        disabled={disabled}
        name="title"
        id={`title${index}`}
        required
        label="Title"
      />
      <Checkbox
        disabled={disabled}
        name="completed"
        id={`completed${index}`}
        label="Completed"
      />
    </>
  );
}

const TODOS_URL = 'https://jsonplaceholder.typicode.com/todos';
const MyForm = () => (
  <RestApiCrudForm
    name="todoList"
    resourceUrl={TODOS_URL}
    urlForRead={`${TODOS_URL}?userId=${USER_ID}`}
    inputComponent={Todo}
  />
);

export default MyForm;

Features

  • Easy to write mult-row CRUD Forms connected to a rest api (See live example)
  • Optimized for efficient rendering (See live example)
  • Small bundle size (see bundlephobia)
  • React-native support
  • Perfect for server-rendering
  • Stores values as semantic types, eg number fields will store numbers
  • Format values, eg to put commas in numbers
  • Field-arrays for repeated rows with add/remove
  • Keeps a running error-count and valid/not valid status
  • Synchronous and asynchronous validation
  • Easy inter-field valiation (See live example)

Contributing contributions welcome

I'm keen to get feedback and to work collaboratively. Please let me know about any issues/ideas here.


Go to live examples, code and docs.