Something went wrong. Try again.
hardened bluesky app fork with microcosm
Something went wrong. Try again.
12345678910111213141516171819202122232425import {useCallback, useRef} from 'react'import {type AppBskyFeedDefs} from '@atproto/api'
/** * Hook that returns a callback to track post:view events. * Handles deduplication so the same post URI is only tracked once per mount. * * @param logContext - The context where the post is being viewed * @returns A callback that accepts a post and logs the view event */export function usePostViewTracking(logContext: string) { const seenUrisRef = useRef(new Set<string>())
const trackPostView = useCallback( (post: AppBskyFeedDefs.PostView) => { if (seenUrisRef.current.has(post.uri)) return seenUrisRef.current.add(post.uri)
}, [logContext], )
return trackPostView}