Skip to content

JoviDeCroock/Hooked-Form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Hooked-Form

npm version All Contributors Build Status Bundle size codecov

Documentation

Example

๐ŸŒ Installation

yarn

  yarn add hooked-form

npm

  npm i --save hooked-form

UMD

dev:

<script src="https://unpkg.com/hooked-form@latest/dist/hooked-form.umd.js"></script>

๐ŸŽจ Example

import React from 'react';
import { HookedForm, useField } from 'hooked-form';

const StringField = ({ fieldId, label }) => {
  const [{ onChange }, { touched, error, value }] = useField(fieldId);
  const onInput = React.useCallback(e => onChange(e.currentTarget.value), [
    onChange,
  ]);
  return (
    <label>
      {label + ' '}
      <input value={value} onChange={onInput} />
      {touched && error && <div>{error}</div>}
    </label>
  );
};

const App = () => {
  return (
    <HookedForm
      onSubmit={console.log}
      validateOnBlur
      initialValues={React.useMemo(() => ({ name: '' }), [])}
      validate={values => (values.name ? {} : { name: 'Required' })}
    >
      <h3>Hooked Form</h3>
      <StringField label="Name:" fieldId="name" />
      <input type="submit" value="Submit" />
    </HookedForm>
  );
};

render(<App />, document.body);

๐Ÿ’ฟ Modern build

This library offers a modern build (ES2015 output), this is smaller and parses faster in the browser. So if you don't plan to target older browsers feel free to use this.

Webpack

  "resolve": {
    "alias": {
      "hooked-form": "hooked-form/dist/hooked-form.modern.js"
    }
  }

Parcel

  "alias": {
    "hooked-form": "hooked-form/dist/hooked-form.modern.js"
  }

๐Ÿ“ข Credits

๐Ÿ˜Contributors

Thanks goes to these wonderful people (emoji key):


Laurens Lavaert

๐Ÿ’ป

Jovi De Croock

๐Ÿš‡ โš ๏ธ ๐Ÿ‘€ ๐Ÿ“– ๐Ÿ’ป

Jonathan Callewaert

๐Ÿ›

Andrew Rempe

๐Ÿ’ป

Corentin Leruth

๐Ÿ’ป

Pavel Ravits

๐Ÿ›

Tegan Churchill

๐Ÿ›

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Performant 2KB React library to manage your forms

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 8