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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-form-addons

v4.0.0

Published

Compose simple and nested forms with Higher-order components / decorators in React

Downloads

16

Readme

react-form-addons

Utility belt for building forms with functional components in React.

Build Status npm package PRs Welcome

About

react-form-addons enables the construction of simple or nested forms in React while keeping the components as functional components.

The library abstracts possible data input patterns like lists of data, nested form data or even conditional form data into Higher-Order functions, and ultimately builds and exposes a final "formData" and "formMeta" to your chosen state engine.

It is independent of state libraries, i.e. if you want to use React Component State, Redux or any other state management engine, you should be able to do so with minimal effort.

For examples, check out the React Component State or Redux State implementations.

Table of Contents

core (lib)

utils

extensions

components

Installation

Install the library:

npm install react-form-addons --save

// or

yarn add react-form-addons

Quick Look

import React from 'react';
import {compose, withProps, withState} from 'react-form-addons';

const Form = (props) => (
  <div>
    <input
      name='input1'
      onChange={props.onChange}
      value={props.getFormData('input1')}
    />
    // Or just access the property
    <input
      name='input2'
      onChange={props.onChange}
      value={props.formData.input2}
    />
    // ...other inputs
  </div>
);

export default compose(
  withState(),
  withProps()
)(Form);

For more examples, check out the documentation site

v2 Upgrade

This library has been totally reworked for v2. As such there are some breaking changes in the way the higher-order components (hoc) work. The biggest change is that Component properties are now decoupled to a withProps hoc and withState only handles keeping of state and not any of the state manipulations.

The following are temporarily deprecated.

It may make a comeback in a future release.

  • createField
  • createForm

Method renames:

  • what used to be collection() is now branch()
  • what used to be connect() is now collection()

Checkout the v2.0.0 release notes

Form Event Normalization

Your event handlers will be passed instances of SyntheticFormEvent when it's piped through withProps onChange handler.

It inherits target.name, target.value, stopPropagation() and preventDefault() from React's Event System and adds on 2 sub-properties formData and formMeta.

The 2 sub-properties are heavily used to calculate and update the current state of the form within the compose pipeline.

Extending Usage

While the focus on v2 rewrite still hinges on Component State, we can easily extend this to other state management utilities.

For example, in it's simplest form:

export default compose(
  withState(),
  withProps()
)(Form);

can become

export default compose(
  withLocalStorage(),
  withProps()
)(Form);

Redux Support

This library also provides a component for handling state in redux. You'll need to install react-redux as well as redux for it to work.

Note: Redux components are not under default library export. As such, you'll have to import from a sub folder. i.e.

import {withReduxState, formReducer} from 'react-form-addons/redux';

// Creating stores
const reducers = combineReducers({
  forms: formReducer
});

const store = createStore(reducers);

// During form composition
const Form = compose(
  withReduxState(),
  withProps()
)(FormInputs);

// Usage (note: prop "name" is required)
<Form name='example' />

Prior Art

The implementation of a compose methodology was highly inspired by react-reformed.

License

react-form-addons is MIT licensed