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

v3.0.2

Published

Simple non opinionated form hook

Downloads

29

Readme

react-clean-form

react-clean-form is a component with goal of being a composable, un-opinionated form component that makes it easy to get a quick and easy form into your react app with out a lot of boilerplate code. react-clean-form manages state for you so you can simply bring it in to your project, add in form fields that use the name prop that corresponds to the properties in the initialState prop, and add a handleSubmit function to the onSubmit prop to capture the state of the form at submission. There is no need to add the value prop to your form fields, react-clean-form handles that for you. react-clean-form will reset the form to the initial state if a reset event is fired.

react-clean-form forwards the ref to the form element itself and all other props are passed directly to the form element, including className and style.

react-clean-form now exports a useForm hook that takes in an initialState and returns the form state and handleChange function in array, similar to useState

Installation

npm install react-clean-form

Usage

Form Component

import Form from 'react-clean-form';

const App = () => (
  <div>
    <Form initialState={{ input: '' }} onSubmit={handleSubmit}>
      <input name="input" />
      <button type="submit">Submit</button>
      <button type="reset">Reset</button>
    </Form>
  </div>
);

useForm Hook

import {useForm} from 'react-clean-form';

const App = () => (
  const [formState, handleChange] = useForm({ input: '' });
  <div>
    <form onReset={handleChange}>
      <input name="input" onChange={handleChange} value={formState['input']} />
      <button type="submit">Submit</button>
      <button type="reset">Reset</button>
    </form>
  </div>
);

Props

| name | type | default | description | | ------------ | :------: | :----------: | -------------------------------------------------------------------------------------------------- | | initialState | Object | empty Object | The initial state of the form | | onSubmit | function | no-op | callback that will be called when the form is submitted the form state is passed into the function |

Contributing

In lieu of a formal style guide, please format your code using 'prettier' prior to commit.

Release History

  • 3.0.1- 3.0.2 added Typescript and updated to React Hooks. useForm hook exported as a named export.
  • 2.1.3 fixed webpack build issue that was bundling react
  • 2.1.1 - 2.1.2 Bug fix when value's were not set on mounting and when child is null
  • 2.1.0 Improved functionality with multiple form elements
  • 2.0.1 - 2.0.2 Bug Fix and documentation fix
  • 2.0.0 Removed the need to render children as a function.
  • 1.0.1 - 1.0.2 Documentation update
  • 1.0.0 Initial Stable Release