mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useEffect} from 'react'
2import EventEmitter from 'eventemitter3'
3
4const events = new EventEmitter<{
5 emailVerified: void
6}>()
7
8export function emitEmailVerified() {
9 events.emit('emailVerified')
10}
11
12export function useOnEmailVerified(cb: () => void) {
13 useEffect(() => {
14 /*
15 * N.B. Use `once` here, since the event can fire multiple times for each
16 * instance of `useAccountEmailState`
17 */
18 events.once('emailVerified', cb)
19 return () => {
20 events.off('emailVerified', cb)
21 }
22 }, [cb])
23}