I have a react application that is giving a linting error:
Promise-returning function provided to attribute
where a void return was expected
.eslint@typescript-eslint/no-misused-promises
The function looks like this
<Button onClick={
async () => {
await handleDelete()
}}
>
I’ve tried adding return void
along with a number of different ways to wrap the code and add catch as suggested in various SO posts but none of them worked to resolve the error.
I do not wish to disable the rule without understanding why – and once I do it will probably be to remove or disable the rule in the lint config
2
Answers
There are two approaches here:
You can learn more about IIFE on: MDN Official Docs
no-misused-promises
rule.For project wide, add rule in
.eslintrc
:To disable this inline, comment this above the particular occurrence to ignore the error.
You could read about it more on: GitHub ESLint Docs
In this particular case you can safely skip using
async
, because there is no need for eitherhandleDelete
result or async flow controlIn other scenarios the documentation for the
no-misused-promises
rule suggests 2 approaches:ref: https://typescript-eslint.io/rules/no-misused-promises/#checksvoidreturn