diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-06-10 23:29:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-10 15:29:39 -0500 |
commit | 1380c5ac67c937b84dd5d7172fbb660c45d0c87c (patch) | |
tree | fd0f1c0fd156e07961c160ab93ea533c0f42ac16 /src/state | |
parent | c6fc298d1e472f53bf7eeeca24f87f796a473f2c (diff) | |
download | voidsky-1380c5ac67c937b84dd5d7172fbb660c45d0c87c.tar.zst |
use ref instead of source (#8471)
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/unstable-post-source.tsx | 31 |
1 files changed, 10 insertions, 21 deletions
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<Map<string, Source>>(() => new Map()) + const sourcesRef = useRef<Map<string, Source>>(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 ( <SetUnstablePostSourceContext.Provider value={setUnstablePostSource}> |