use-controlled-form

0.0.17 • Public • Published

use-controlled-form

npm CircleCI

Create simple controlled React forms, using hooks ⚓, without all the fluff!

🚨 use-controlled-form requires React >= 16.8 🚨

Installation

Install with NPM:

npm i use-controlled-form

Install with Yarn:

yarn add use-controlled-form

Basic Usage

import useForm from "use-controlled-form";
 
function LoginForm() {
  const { fields, onSubmit } = useForm({
    initialValues: {
      username: "",
      password: ""
    },
    onSubmit: values => {
      console.log(values); // { username: 'foo', password: 'bar' }
    }
  });
 
  return (
    <form onSubmit={onSubmit}>
      <input {...fields.username} />
      <input type="password" {...fields.password} />
      <button type="submit">Login</button>
    </form>
  );
}
 
export default LoginForm;

Package Sidebar

Install

npm i use-controlled-form

Weekly Downloads

1

Version

0.0.17

License

MIT

Unpacked Size

5.11 kB

Total Files

3

Last publish

Collaborators

  • coreyleelarson