@guirdo/simple-use-form

1.0.7 • Public • Published

simple-use-form

A simple custom hook for managing the form state.

Usage

Most of inputs

import useForm from 'simple-use-form'

function App() {
  const {formValues, handleOnChange} = useForm({
    name: 'Joe',
    email: 'joe@mail.com',
  });

  const { name, email } = formValues

  return (
    <form>
      <input 
        name="name"
        value={ name }
        onChange={ handleOnChange }
      />

      <input 
        name="email"
        value={ email }
        onChange={ handleOnChange }
      />
    </form>
  )
}

Radio inputs

const {formValues, handleOnChange} = useForm({
  single: 'no',
});

const { name, email } = formValues

return (
  <form>
    <label>
      Single ?:
    </label>
    <label>
      Yes
      <input
        name="single"
        type="radio"
        value="yes"
        defaultChecked={ single === 'yes' }
        onChange={ handleChange }
      />
    </label>

    <label>
      No
      <input
        name="single"
        type="radio"
        value="no"
        defaultChecked={ single === 'no' }
        onChange={ handleChange }
      />
    </label>
)

Readme

Keywords

Package Sidebar

Install

npm i @guirdo/simple-use-form

Weekly Downloads

0

Version

1.0.7

License

none

Unpacked Size

5.83 kB

Total Files

5

Last publish

Collaborators

  • guirdo