From 3bfb2f8035ad150e784ce63a4236e9ba13f8a8df Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 9 Jun 2026 15:57:22 -0500 Subject: [PATCH] Feedback, use ref --- src/state/cache/profile-shadow.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/state/cache/profile-shadow.ts b/src/state/cache/profile-shadow.ts index d911401b02..430a03577f 100644 --- a/src/state/cache/profile-shadow.ts +++ b/src/state/cache/profile-shadow.ts @@ -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 QueryClient} from '@tanstack/react-query' import {EventEmitter} from 'eventemitter3' @@ -57,12 +57,19 @@ type ShadowUpdateEventPayload = {did: string; shadow: Partial} export function useOnUpdateProfileShadow( onUpdate: (payload: ShadowUpdateEventPayload) => void, ) { + const onUpdateRef = useRef(onUpdate) + // eslint-disable-next-line react-hooks/refs + onUpdateRef.current = onUpdate + useEffect(() => { - emitter.addListener('shadow-update', onUpdate) - return () => { - emitter.removeListener('shadow-update', onUpdate) + function listener(payload: ShadowUpdateEventPayload) { + onUpdateRef.current(payload) } - }, [onUpdate]) + emitter.addListener('shadow-update', listener) + return () => { + emitter.removeListener('shadow-update', listener) + } + }, []) } export function useProfileShadow<