0.0.8 • Published 4 years ago

@fishx/form v0.0.8

Weekly downloads
41
License
-
Repository
-
Last release
4 years ago

@fishx/form

React form based on Hooks

Installation

yarn add @fishx/form

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import { createForm } from '@fishx/form'

const { Field, store } = createForm({
  initialValues: {
    email: '',
    password: '',
  },
  onSubmit: async (values, { setSubmitting }) => {
    alert(JSON.stringify(values, null, 2))
    setSubmitting(false)
  },
})

const App = () => {
  return (
    <form onSubmit={store.handleSubmit}>
      <Field name="email">
        <input type="text" />
      </Field>

      <Field name="password">
        <input type="password" />
      </Field>
      <button type="submit" disabled={store.submitting}>
        submit
      </button>
    </form>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))