wardxela
wardxela
TTCTheo's Typesafe Cult
Created by Xaohs on 9/15/2023 in #questions
Anyone can help me with this React-Hook-Form problem?
Hello, handleSubmit is a higher order function and should be called in the following way:
<form
onSubmit={handleSubmit(onSubmit, onError)}
>
</form>
<form
onSubmit={handleSubmit(onSubmit, onError)}
>
</form>
By the way, handleSubmit handles e.prevenDefault under the hood, so you don't need to worry about it yourself. Technically your code will start to work if you will call the function, that handleSubmit return:
const form = useForm<TFormValues>({
resolver: zodResolver(FormSchema),
defaultValues,
});
return (
<form
onSubmit={(e) => {
e.preventDefault();
console.log("Submitting...");
form.handleSubmit(
(data) => {
console.log(data);
},
(errors) => {
console.log(errors);
}
)(e) // NOTE CALL HERE
}}
>
<input type='text' {...form.register('testName')} />
<input type='submit' />
</form>
const form = useForm<TFormValues>({
resolver: zodResolver(FormSchema),
defaultValues,
});
return (
<form
onSubmit={(e) => {
e.preventDefault();
console.log("Submitting...");
form.handleSubmit(
(data) => {
console.log(data);
},
(errors) => {
console.log(errors);
}
)(e) // NOTE CALL HERE
}}
>
<input type='text' {...form.register('testName')} />
<input type='submit' />
</form>
3 replies
TTCTheo's Typesafe Cult
Created by kesh on 9/14/2023 in #questions
Tailwind grid
Hello, you're right, this layout can be easily made using grid, especially if it is going to be static (like landing page or something) See here https://play.tailwindcss.com/g7AC75H7Yg
6 replies