Skip to content
/ formz Public
forked from successkrisz/formz

React library for painless form management

License

Notifications You must be signed in to change notification settings

batjko/formz

 
 

Repository files navigation

formz

js-standard-style npm version Build Status Coverage Status

React Form library to provide html like experience when building forms without having to worry about state

Install

Install package using yarn

yarn add @ballatech/formz

Usage

import React from 'react'
import { Form, useForm, FormContext } from '@ballatech/formz'

const validator = (value, fields) => value.length < 5 ? 'Too short' : null

const Component = () => {
  const { value, setField } = useForm('username', '', validator)

  return (
    <input
      name="username"
      onChange={e => setField(e.target.value)}
      value={value}
    />
  )
}

const Reset = () => {
  const { reset } = React.useContext(FormContext)

  return <button onClick={reset}>Reset</button>
}

const Submit = () => {
  const { isValid } = React.useContext(FormContext)

  return <button disabled={!isValid} type="submit">Submit</button>
}

const MyCoolForm = ({ onSubmit }) => (
  <Form onSubmit={onSubmit}>
    <Component />
    <Submit>
    <Reset />
  </Form>
 )

 export default MyCoolForm

About

React library for painless form management

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%