In this article, we will learn how to use setvalues in useform using react js
using setvalue variable we have to add values of any of the filed in useform. you can see following code.
import React, { useEffect } from 'react' import { useForm } from "react-hook-form"; export default function Setvaluecomponent() { const { register, handleSubmit, setValue, formState: { errors }, } = useForm(); const onSubmit = () => { console.log("submit") } useEffect(() => { setValue('name', "himani vgahsiya") }, []) return ( <form onSubmit={handleSubmit(onSubmit)}> <h2>Edit value</h2> <input type="text" name="name" {...register("name")} /> <button type='submit'>submit</button> </form> ) }
you can see below the output,