-
I am having a typescript-eslint error checked this one which is also recommended on react-hook-form website, following the same. We are using |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 22 replies
-
Try typing your submit handler this way instead: import type { SubmitHandler } from "react-hook-form"
const onSubmit: SubmitHandler<FormValues> = (data) => {} |
Beta Was this translation helpful? Give feedback.
-
Has anyone solved this? I'm running into the same issue. Is this a typescript version issue?
|
Beta Was this translation helpful? Give feedback.
-
@Adnan0061 @rtman The first is to wrap the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
For those who do not want to disable the eslint rules. I solved it by passing a anonymous function with the <form
onSubmit={(event) =>
void handleSubmit(onSubmit)(event)
}
> |
Beta Was this translation helpful? Give feedback.
-
I still think this goes beyond "it's just eslint" or "tsconfig rule". Different ways of writing this causes different outcomes. I started with this <form onSubmit={form.handleSubmit(onSubmit)}> Which yields this error: "Promise-returning function provided to attribute where a void return was expected". Which makes sense because you're trying to assign a Promise returning function to onSubmit which expects void. You can do this but this seems to skip any validators you have like a zod schema. It also submits your form as query params. <form onSubmit={(event) => void form.handleSubmit(onSubmit)}> Passing the event to the previous example seems to work as expected which I got from @RubenSmn 's answer. <form onSubmit={(event) => void form.handleSubmit(onSubmit)(event)}> But If you want to go for extra measures you could do it like this as well, <form onSubmit={(event) => {
event.preventDefault();
void form.handleSubmit(onSubmit)(event);
}}> |
Beta Was this translation helpful? Give feedback.
-
It looks like this could be also be written more elegantly like: <form onSubmit={void handleSubmit(onSubmit)} /> Unless I'm missing something? |
Beta Was this translation helpful? Give feedback.
-
I am facing the same Promise-returning function provided to attribute where a void return was expected. onSelect={async (props) => { |
Beta Was this translation helpful? Give feedback.
-
We have solved this with a helper function
Usage
In our case the actual |
Beta Was this translation helpful? Give feedback.
#9325 (comment)