Giter VIP home page Giter VIP logo

react-clean-form's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.