An open API service indexing awesome lists of open source software.

https://github.com/angelhtml/react_hook_yup

react hook form with yup example
https://github.com/angelhtml/react_hook_yup

angelcodestyle axios axios-react cors expressjs form javascript jsx nextjs nodejs reacthookform reactjs validation yup yup-validation

Last synced: 3 months ago
JSON representation

react hook form with yup example

Awesome Lists containing this project

README

          

React Hook Form


angel code style

manage your data using with react hook form and yup and send it to your server

📜libraries



  • React js or Next js

  • React hook form

  • yup

  • Axios

  • Express js

  • Cors

in client folder you can see the react hook form and yup tool and axios that can send your data to server

``` javascript
const userSchema = yup.object().shape({
Username: yup.string().required(),
Age: yup.string().required(),
});

const { register:registeruser, handleSubmit:handleSubmituser, formState: { errors:errorsuser }, reset:resetuser } = useForm({
resolver: yupResolver(userSchema),
});
//posting your data from yup to server
const onSubmitHandleruser = (data) => {
axios({
method: 'post',
url: `http://localhost:3001/api/user`,
data: data,
})
.then(function (response) {
setDatas(response.data)
setLoading(true)
//console.log(response)
}).catch(function (error) {
console.log(error);
})
};
```

the server folder is a basic express server that will be available response your requests

``` javascript
app.post("/api/user", (req, res) => {
const username = req.body.Username;
const age = req.body.Age;
res.send({"name" : username, "age" : age})
console.log("data receive")
});
```