Skip to content

onComplete method need to wait for API call response #161

Answered by vydimitrov
DapperNerd asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, yup async await returns Promise, which breaks the code since onComplete expects either an array or nothing as a returned value. You can do the following:

const [key, setKey] = useState(0)

.
.
.

<CountdownTimer
  key={key}
  onCopmplete={() => {
     (async () => {
        // do your async stuff here
       // if you need to repeat the timer just set the key and the timer will start over again
      setKey(prev => prev + 1)
     })()
  }}
/>

(async() => {})() is this one

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@DapperNerd
Comment options

@vydimitrov
Comment options

Answer selected by DapperNerd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants