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-declare-form

v0.0.4

Published

Declarative approach to building forms with hooks behind the scenes

Readme

react-declare-form

A declarative approach towards building forms in react

NOTE: This project uses react hooks which are available in alpha.

View the RFC here

About

The purpose of react-declare-form is encapsulate form state management into a root component which wraps children (input, button, select) to allow a declarative way of building up forms.

react-declare-form supports handling of required components by defining a callback function which returns if a form component has been filled out or not. It also supports passing up errors. Both of these objects are available throughout all form components which allows error messages to be displayed around buttons and other form components for example.

react-declare-form only exports two elements. A root form component Form which should be provided with wrapped components. Components should be wrapped using connectToForm function which provides props to the form components to be used in fetching and settings state, errors and required handler logic. Anyone familiar with the Redux style connect function will be comfortable with this pattern. This means that buttons, inputs, selects and other form components need to be wrapped and built and are not provided.

API

Form Components

NOTE: Each form component should have a stateKey and initialStateKey prop provided. Both of these should be unique as they identify that particular components state throughout the form.

TODO

Example

let Input = props => (
  <input
    value={props.componentState || ''}
    onChange={e => {
      e.preventDefault();
      props.setFormState(
        event.target.value, // state
        event.target.value // meta
      );
    }}
    type="text"
  />
);
Input = connectToForm(Input);

let Button = props => (
  <button onClick={() => props.onButtonClick(props.id)}>
    {this.props.children}
  </button>
);
Button = connectToForm(Button, { setInitialStateCallback: false });

const initialState = { email: '[email protected]' };

const myForm = () => (
  <Form
    onButtonClick={formEvent => {
      // Submit form
      api.post(url, formEvent.state.displayState);
    }}
    initialState={initialState}
  >
    <Input stateKey="email" initialStateKey="email" />
    <Button id="submit">Submit</Button>
  </Form>
);