1.0.0-alpha.1 • Published 5 years ago

hooks-form v1.0.0-alpha.1

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

Hooks Form

This is a simple react form management package based on the new famous Hooks API.

Usage

Install it:

yarn add hooks-form

Then use it!

import React from 'react';
import { Field, Form } from 'hooks-form';
...

// Submit handler
function handleSubmit(data) {
  ...
}

// TextInput component
function TextInput({ label, onChange, value }) {
  return (
    <div className="form-row">
      <label>{label}</label>
      <input type="text" onChange={onChange} value={value || ''} />
    </div>
  );
}

// Render your form
function App() {
  return (
    <Form name="createArticle" onSubmit={handleSubmit}>
      <Field component={TextInput} name="title" label="Title" />
      <Field component={TextInput} name="content" label="Content" />
      <Field component={TextInput} name="author" label="Author" />
      <Field component={TextInput} name="tags" label="Tags" />
      <button type="submit">Publish</button>
    </Form>
  );
}

Documentation

Coming soon...