3.4.1 ā€¢ Published 3 years ago

usetheform v3.4.1

Weekly downloads
144
License
MIT
Repository
github
Last release
3 years ago

:bulb: What is usetheform about?

Welcome! šŸ‘‹ Usetheform is a React library for composing declarative forms and managing their state. It does not depend on any external library, such as Redux, or MobX, which makes it easy to adopt due to the lack of dependencies.

:fire: Features

:zap: Quickstart

npm install --save usetheform
import React from "react";
import { Form, Input, useValidation } from "usetheform";

const preventNegativeNumber = (next, prev) => (next <= 0 ? 0 : next);
const required = (value) =>
    value && value.trim() !== "" ? undefined : "Required";

export default function App() {
  const onChange = (formState) => console.log("ON_CHANGE : ", formState);
  const onSubmit = (formState) => console.log("ON_SUBMIT : ", formState);

  const [status, validation] = useValidation([required]);

  return (
    <Form onSubmit={onSubmit} onChange={onChange}>
      <Input name="firstname" type="text" touched {...validation} />
      {status.error && <span>{status.error}</span>}
      <Input name="lastname" type="text" />
      <Input name="age" type="number" value={18} reducers={preventNegativeNumber} />
      <button type="submit">Submit</button>
    </Form>
  );
}

Motivation

usetheform has been built with the necessity of developing a lightweight library in mind, which is able to provide an easy API and allows you to build complex forms, composed by nested levels (e.g. arrays, objects, custom inputs, etc.), with a declarative approach and without the need to include external libraries within your React projects.

It's easy to start using it in your existing project and gives you full control over Field and Collection at any level of nesting, which makes it easy to manipulate the form state based on your needs. Synchronous and asynchronous validations are also simple and error messages are easy to customize and display. If you find it useful please leave a star šŸ™šŸ».

Author

ā†³ Stargazers

Stargazers repo roster for @iusehooks/usetheform

Code Sandboxes

  • Twitter 'What's Happening' Form Bar: Sandbox
  • Shopping Cart: Sandbox
  • Examples: Slider, Select, Collections etc..: Sandbox
  • Various Implementations: Sandbox
  • Wizard: Sandbox
  • FormContext: Sandbox
  • Material UI - React Select: Sandbox
  • Validation using Yup, ZOD, JOI, Superstruct: Sandbox
  • React Dropzone - Material UI Dropzone: Sandbox

How to Contribute

šŸŽ‰ First off, thanks for taking the time to contribute! šŸŽ‰

We would like to encourage everyone to help and support this library by contributing. See the CONTRIBUTING file.

License

This software is free to use under the MIT license. See the LICENSE file for license text and copyright information.

3.4.1

3 years ago

3.4.1-alpha.4

3 years ago

3.4.1-alpha.3

3 years ago

3.4.1-alpha.2

3 years ago

3.4.1-alpha.0

3 years ago

3.4.1-alpha.1

3 years ago

3.4.0

3 years ago

3.4.0-alpha.0

3 years ago

3.3.1

3 years ago

3.3.1-alpha.0

3 years ago

3.3.0

3 years ago

3.3.0-beta.0

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

4 years ago

3.0.0-beta.1

4 years ago

3.0.0-beta.0

4 years ago

3.0.0-alpha.10

4 years ago

3.0.0-alpha.9

4 years ago

3.0.0-alpha.7

4 years ago

3.0.0-alpha.8

4 years ago

3.0.0-alpha.6

4 years ago

3.0.0-alpha.5

4 years ago

3.0.0-alpha.4

4 years ago

3.0.0-alpha.3

4 years ago

3.0.0-alpha.2

4 years ago

3.0.0-alpha.1

4 years ago

3.0.0-alpha.0

4 years ago

2.0.0

4 years ago

2.0.0-alpha.4

4 years ago

2.0.0-alpha.3

4 years ago

2.0.0-alpha.2

4 years ago

2.0.0-alpha.1

4 years ago

2.0.0-alpha.0

4 years ago

1.1.0-beta.2

5 years ago

1.1.0-beta.1

5 years ago

1.1.0-beta.0

5 years ago

1.0.1-beta.0

5 years ago

1.0.0

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha

5 years ago