I ant to implement a form with react-hook-form. I tried this:
....
<form onSubmit={handleSubmit(onSubmit)} className='mt-4 register-form'>
<div className='row'>
<div className='col-sm-6'>
<div className='input-group mb-3'>
<Controller
control={control}
name={"name"} // the key of json
defaultValue={""}
render={({ field }) => (
<input
{...field}
type="text"
className="form-control"
placeholder="Name"
aria-label="name"
onChange={(e) => field.onChange(e.target.value)}
/>
)}
/>
</div>
</div>
.....
Full page code:
When I submit the form I send a POST message using:
import axios from "axios";
import React from "react";
const baseURL = "https://jsonplaceholder.typicode.com/posts";
export const SubmitContact = (json) => {
return axios.post(baseURL, json);
};
But there is no validation message into the form and no final message that the form is successfully summitted.
Do you know how I can implement this functionality?
setPostin youronSubmitis reached, sending the data worked (also note that you called the parameterjsonbut it's an object, not json; json is a text format that looks like a JS object literal) (also the initial value ofpostshould be{})