From 1380c5ac67c937b84dd5d7172fbb660c45d0c87c Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 10 Jun 2025 23:29:39 +0300 Subject: use ref instead of source (#8471) --- src/state/unstable-post-source.tsx | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/state/unstable-post-source.tsx b/src/state/unstable-post-source.tsx index 1fb4af287..43aac6f4d 100644 --- a/src/state/unstable-post-source.tsx +++ b/src/state/unstable-post-source.tsx @@ -1,4 +1,4 @@ -import {createContext, useCallback, useContext, useState} from 'react' +import {createContext, useCallback, useContext, useRef, useState} from 'react' import {type AppBskyFeedDefs} from '@atproto/api' import {type FeedDescriptor} from './queries/post-feed' @@ -22,30 +22,19 @@ const ConsumeUnstablePostSourceContext = createContext< >(() => undefined) export function Provider({children}: {children: React.ReactNode}) { - const [sources, setSources] = useState>(() => new Map()) + const sourcesRef = useRef>(new Map()) const setUnstablePostSource = useCallback((key: string, source: Source) => { - setSources(prev => { - const newMap = new Map(prev) - newMap.set(key, source) - return newMap - }) + sourcesRef.current.set(key, source) }, []) - const consumeUnstablePostSource = useCallback( - (uri: string) => { - const source = sources.get(uri) - if (source) { - setSources(prev => { - const newMap = new Map(prev) - newMap.delete(uri) - return newMap - }) - } - return source - }, - [sources], - ) + const consumeUnstablePostSource = useCallback((uri: string) => { + const source = sourcesRef.current.get(uri) + if (source) { + sourcesRef.current.delete(uri) + } + return source + }, []) return ( -- cgit 1.4.1