43
rated 0 times
[
47]
[
4]
/ answers: 1 / hits: 6323
/ 3 Years ago, wed, april 7, 2021, 12:00:00
When using react-hook-form
I need to pass arbitrary data into the onSubmit
function. Example code:
function App() {
const { register, handleSubmit } = useForm();
const navigation = { foo: 'bar' }; // object to pass
const onSubmit = (data) => {
// how to access navigation here?
console.log(data);
console.log(navigation); // undefined
};
return (
<form onSubmit={handleSubmit(onSubmit)}> // <<== pass navigation here as arg?
<input defaultValue="test" {...register("example")} />
<input type="submit" />
</form>
);
}
How can I pass my object navigation
into onSubmit
?
More From » reactjs