React Hook Form: Validation not triggering on input change despite using `setValue` and `trigger`
I'm relatively new to this, so bear with me... I'm currently working on a form using React Hook Form (version 7.29.0) and I encountered an scenario where the validation isn't triggering when I programmatically set a value using `setValue`. I'm trying to validate the field on change, but it seems like the validation logic isn't being executed as expected. Here's what I've tried so far: 1. I've set up my form using `useForm` from React Hook Form. 2. I've utilized `setValue` to set the input programmatically in a `useEffect` hook based on some external data. 3. I called `trigger` after using `setValue`, but the validation message does not appear. Here's a snippet of my code: ```javascript import React, { useEffect } from 'react'; import { useForm } from 'react-hook-form'; const MyForm = () => { const { register, handleSubmit, setValue, trigger, formState: { errors } } = useForm(); useEffect(() => { // Simulating receiving external data const externalData = "123"; setValue('myInput', externalData); trigger('myInput'); }, []); const onSubmit = data => { console.log(data); }; return ( <form onSubmit={handleSubmit(onSubmit)}> <input {...register('myInput', { required: 'This field is required', minLength: { value: 4, message: 'Minimum length is 4' } })} /> {errors.myInput && <span>{errors.myInput.message}</span>} <button type="submit">Submit</button> </form> ); }; export default MyForm; ``` In this case, `errors.myInput` is `undefined` even after the `setValue` and `trigger` calls. I've checked if the validation rules are being applied correctly, and they seem fine. I'm not sure if it's an scenario with the timing of when `trigger` is called or something else entirely. Any suggestions on how to make the validation trigger as expected? My development environment is Linux. Am I missing something obvious?