I declared a state to save the user Info from react hook form and then pass the email and password value to the firebase authentication function. In the first click, it shows an error and in the second click, it works.
// User Info
const [userInfo, setUserInfo] = useState({});
// React Hook Form
const { register, handleSubmit, formState: { errors } } = useForm();
const onSubmit = data => setUserInfo(data);
console.log(userInfo);
const { email, password } = userInfo;
const [
createUserWithEmailAndPassword,
user,
loading,
error,
] = useCreateUserWithEmailAndPassword(auth);
const handleSignup = () => {
createUserWithEmailAndPassword(email, password);
}