@usereact/use-yup

react hook for yup validations

Usage no npm install needed!

<script type="module">
  import usereactUseYup from 'https://cdn.skypack.dev/@usereact/use-yup';
</script>

README

useYup

react hook for yup validations

NPM

Install

npm install --save @usereact/use-yup

Usage

``tsx import React, { useState } from 'react' import useYup from '@usereact/use-yup'

const validationSchema = yup.object().shape({ name: yup.string().required(), email: yup.string().required(), })

function Example() { const [values, setValues] = useState({ name: '', email: '', })

const { errors, validate } = useYup(values, validationSchema, { validateOnChange: true }) console.log('errors: ', errors)

const handleChange = e => { const { name, value } = e.currentTarget setValues(prevState => ({ ...prevState, [name]: value })) }

return (

) } ```

License

MIT © JuHwon