Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use ref instead of source (#8471)

authored by

Samuel Newman and committed by
GitHub
1380c5ac c6fc298d

+10 -21
+10 -21
src/state/unstable-post-source.tsx
··· 1 - import {createContext, useCallback, useContext, useState} from 'react' 1 + import {createContext, useCallback, useContext, useRef, useState} from 'react' 2 2 import {type AppBskyFeedDefs} from '@atproto/api' 3 3 4 4 import {type FeedDescriptor} from './queries/post-feed' ··· 22 22 >(() => undefined) 23 23 24 24 export function Provider({children}: {children: React.ReactNode}) { 25 - const [sources, setSources] = useState<Map<string, Source>>(() => new Map()) 25 + const sourcesRef = useRef<Map<string, Source>>(new Map()) 26 26 27 27 const setUnstablePostSource = useCallback((key: string, source: Source) => { 28 - setSources(prev => { 29 - const newMap = new Map(prev) 30 - newMap.set(key, source) 31 - return newMap 32 - }) 28 + sourcesRef.current.set(key, source) 33 29 }, []) 34 30 35 - const consumeUnstablePostSource = useCallback( 36 - (uri: string) => { 37 - const source = sources.get(uri) 38 - if (source) { 39 - setSources(prev => { 40 - const newMap = new Map(prev) 41 - newMap.delete(uri) 42 - return newMap 43 - }) 44 - } 45 - return source 46 - }, 47 - [sources], 48 - ) 31 + const consumeUnstablePostSource = useCallback((uri: string) => { 32 + const source = sourcesRef.current.get(uri) 33 + if (source) { 34 + sourcesRef.current.delete(uri) 35 + } 36 + return source 37 + }, []) 49 38 50 39 return ( 51 40 <SetUnstablePostSourceContext.Provider value={setUnstablePostSource}>