A
A
Alexander2021-09-19 18:57:56
React
Alexander, 2021-09-19 18:57:56

Is it correct to use async await when dealing with callbacks?

Is it correct to use async await when dealing with callbacks?
I have a callback onClose which closes the menu and dispatch(showModal()) which opens the modal via redux. It is necessary that when clicking on one button, two callbacks are executed in turn, that is, the onClose function must first complete, and then dispatch. I tried to use async await for this situation, everything works fine, only the question arose whether such a record is correct, because I have not seen such code anywhere

const handleSignIn = async () => {
    await onClose()
    dispatch(
      showModal({
        modalType: 'login',
        mounted: true,
        modalProps: {
          title: 'YOUR ACCOUNT FOR EVERYTHING NIKE',
          description: '',
          logo: true,
        },
      })
    )
  }

 <Button onClick={handleSignIn}>Sign In</Button>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2021-09-19
@axrising

an async function returns a promise, that's all. If onClick is on the drum, then everything is fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question