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;
-
Notifications
You must be signed in to change notification settings - Fork 0
easy to use react hook to mange form inputs, validations and api calls.
License
abdheshnayak/react-useform
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
easy to use react hook to mange form inputs, validations and api calls.