Feedback, use ref
This commit is contained in:
committed by
Samuel Newman
parent
e592fa7e49
commit
3bfb2f8035
Vendored
+12
-5
@@ -1,4 +1,4 @@
|
|||||||
import {useEffect, useMemo, useState} from 'react'
|
import {useEffect, useMemo, useRef, useState} from 'react'
|
||||||
import {type AppBskyActorDefs, type AppBskyNotificationDefs} from '@atproto/api'
|
import {type AppBskyActorDefs, type AppBskyNotificationDefs} from '@atproto/api'
|
||||||
import {type QueryClient} from '@tanstack/react-query'
|
import {type QueryClient} from '@tanstack/react-query'
|
||||||
import {EventEmitter} from 'eventemitter3'
|
import {EventEmitter} from 'eventemitter3'
|
||||||
@@ -57,12 +57,19 @@ type ShadowUpdateEventPayload = {did: string; shadow: Partial<ProfileShadow>}
|
|||||||
export function useOnUpdateProfileShadow(
|
export function useOnUpdateProfileShadow(
|
||||||
onUpdate: (payload: ShadowUpdateEventPayload) => void,
|
onUpdate: (payload: ShadowUpdateEventPayload) => void,
|
||||||
) {
|
) {
|
||||||
|
const onUpdateRef = useRef(onUpdate)
|
||||||
|
// eslint-disable-next-line react-hooks/refs
|
||||||
|
onUpdateRef.current = onUpdate
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
emitter.addListener('shadow-update', onUpdate)
|
function listener(payload: ShadowUpdateEventPayload) {
|
||||||
return () => {
|
onUpdateRef.current(payload)
|
||||||
emitter.removeListener('shadow-update', onUpdate)
|
|
||||||
}
|
}
|
||||||
}, [onUpdate])
|
emitter.addListener('shadow-update', listener)
|
||||||
|
return () => {
|
||||||
|
emitter.removeListener('shadow-update', listener)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useProfileShadow<
|
export function useProfileShadow<
|
||||||
|
|||||||
Reference in New Issue
Block a user