<div
onClick={async (e) => {
await api_call();
}}
/>
<div
onClick={(e) => {
api_call();
}}
/>
What would be the difference of the 2 above? The api_all is the last line of the callback, so is there any difference at all?
2
Answers
If a function uses async await for handling when being invoked, it can make the function execute synchronously. However, the effect is the same in click events, and asynchronous functions do not exist in the environment of another function.
I think this is an interesting question.
What I know is that eslint has a rule called
no-return-await
. What it does is to check if there is anawait
after thereturn
It says
Without
return
it is probably the same thing. The function that callsawait api_call()
would remain in the call stackIf the function was like that
Then that function would remain in the call stack, other way it would not be possible to call the console log after finishing api_call