Promise-returning function provided to attribute where a void return was expected.

Hello, doing app with t3. I am using react-hook-form and I am getting error from handleSubmit: Promise-returning function provided to attribute where a void return was expected.eslint@typescript-eslint/no-misused-promises
<form onSubmit={handleSubmit(onSubmit)}>
....
</form>
<form onSubmit={handleSubmit(onSubmit)}>
....
</form>
I tried by doing like this but those does not work correctly:
void handleSubmit(onSubmit)
void handleSubmit(onSubmit)
() => handleSubmit(onSubmit)
() => handleSubmit(onSubmit)
How this should be fixed?
9 Replies
barry
barry2y ago
(event) => void handleSubmit(event)
rocawear
rocawear2y ago
I think react hook form prevents it by default(?)
const {
register,
handleSubmit,
formState: { errors },
} = useForm<FormData>({
resolver: zodResolver(schema),
});

const createNewBook = api.books.createBook.useMutation();

const onSubmit = async (data: FormData) => {
await createNewBook.mutateAsync(data);
};
const {
register,
handleSubmit,
formState: { errors },
} = useForm<FormData>({
resolver: zodResolver(schema),
});

const createNewBook = api.books.createBook.useMutation();

const onSubmit = async (data: FormData) => {
await createNewBook.mutateAsync(data);
};
const onSubmit: (data: FormData) => Promise<void>
const onSubmit: (data: FormData) => Promise<void>
barry
barry2y ago
Idk what you’re on about now 😂 what I showed works for this ESLint plug-in problem
rocawear
rocawear2y ago
I mean I dont need the event, I am using react-hook-form
barry
barry2y ago
Of course you need to pass the event
rocawear
rocawear2y ago
Why would I? I have data correctly now but with the ts error https://react-hook-form.com/advanced-usage#CustomHookwithResolver
barry
barry2y ago
Then just don’t pass anything?
rocawear
rocawear2y ago
I am doing like documentation says, but t3 has this rule and not sure how to solve it
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server