I am trying to write a custom onChange and watch the change.
Error:
The watched myValue does not register the changes in the dropdown. Any ideas why?
According to the API documentation, this is possible by doing the following:
export default function App() {
const { register, watch } = useForm();
const fruits = register("fruits");
const myValue = watch("fruits", "default");
return (
<div className="App">
<h1>{myValue}</h1>
<select
onChange={(e) => {
fruits.onChange(e); // react hook form onChange
console.log("Here would go the my onChange"); // my onChange
}}
onBlur={fruits.onBlur}
ref={fruits.ref}
>
<option value="1Banana">Banana</option>
<option value="1Kiwi">Kiwi</option>
<option value="1Mango">Mango</option>
</select>
</div>
);
}
You may find the upper example here: