How can I get data from child components using useForm in the parent component? All my components are react-hooks.
I tried:
SignUp.js:
const { register, handleSubmit } = useForm();
const submitHandler = (data) => {
console.log(data);
};
return (
<div style={{ margin: "3rem" }}>
<form onSubmit={handleSubmit(submitHandler)}>
<Form register={register}>
<button type="submit">Sign Up</button>
</form>
</div>
Form.js:
return(
<div>
<input name="username" ref={props.register}/>
</div>
)
But when I click on submit button I get an empty object {} in the console. Is this the right way or should I add something else?