@kavre/react-useform
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

React Form Hook

example

import React from 'react';
import * as yup from 'yup';
import useForm from '@kavre/react-useform';

const App = () => {
  const {
    values,
    errors,
    handleChange,
    handleSubmit,
    resetValues,
    submit,
    setValues,
  } = useForm({
    initialValues: {
      name: '',
    },
    validationSchema: yup.object({
      name: yup.string().required(),
    }),
    onSubmit: async (values) => {
      console.log(values);
      resetValues();
    },
  });
  return (
    <form onSubmit={handleSubmit}>
      <input onChange={handleChange('name')} value={values.name} />
      <button type="submit">Submit</button>

      {errors.name && <p>{errors.name}</p>}
    </form>
  );
};

export default App;

Package Sidebar

Install

npm i @kavre/react-useform

Weekly Downloads

245

Version

1.1.5

License

MIT

Unpacked Size

23.8 kB

Total Files

6

Last publish

Collaborators

  • abdheshnayak