1.0.4 • Published 2 years ago

simple-react-hook-form v1.0.4

Weekly downloads
7
License
MIT
Repository
github
Last release
2 years ago

simple-react-hook-form

A simple form library for react.js and react native using hooks

NPM JavaScript Style Guide

Edit nostalgic-cookies-xmq8g

Install

npm install --save simple-react-hook-form

Usage

import React, { Component } from 'react'

import useForm from 'simple-react-hook-form'
import * as yup from 'yup'

let initialValues = { name: 'React' }
const validationSchema = yup.object().shape({
  name: yup
    .string()
    .min(5, 'Name must be minimum of length 5')
    .required('Name is required')
})
const App = () => {
  const {
    handleChange,
    resetForm,
    clearForm,
    values,
    handleSubmit,
    errors
  } = useForm(initialValues, {
    validate: true,
    validateSchema: validationSchema,
    validationOnChange: true
  })

  const onSubmit = () => {
    console.log('form is valid, Do what you gotta do!')
  }
  return (
    <div className='App'>
      <form>
        <div>
          <label htmlFor={'Name'}>{'Name'}</label>
          <input
            onChange={(e) => handleChange('name', e.currentTarget.value)}
            name={'name'}
            placeholder={'Please enter name'}
            type={'text'}
            value={values.name}
          />
          {errors.name && <p className='errorText'>{errors.name.join('\n')}</p>}
        </div>

        <button type='button' onClick={() => handleSubmit(onSubmit)}>
          Submit
        </button>
      </form>
    </div>
  )
}

License

MIT © ravisojitra

1.0.4

2 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago