about summary refs log tree commit diff
path: root/src/components/dialogs/EmailDialog/events.ts
blob: 4fa171cad5ec328b2b9252c3bd529f1e0002f869 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import {useEffect} from 'react'
import EventEmitter from 'eventemitter3'

const events = new EventEmitter<{
  emailVerified: void
}>()

export function emitEmailVerified() {
  events.emit('emailVerified')
}

export function useOnEmailVerified(cb: () => void) {
  useEffect(() => {
    /*
     * N.B. Use `once` here, since the event can fire multiple times for each
     * instance of `useAccountEmailState`
     */
    events.once('emailVerified', cb)
    return () => {
      events.off('emailVerified', cb)
    }
  }, [cb])
}