MCPcopy Create free account
hub / github.com/block/buzz / usePanelReturnTarget

Function usePanelReturnTarget

desktop/src/shared/hooks/usePanelReturnTarget.ts:18–40  ·  view source on GitHub ↗
(resetKey: unknown = null)

Source from the content-addressed store, hash-verified

16 * breadcrumbs from leaking across contexts.
17 */
18export function usePanelReturnTarget<T>(resetKey: unknown = null): {
19 hasTarget: boolean;
20 store: PanelReturnTargetStore<T>;
21} {
22 const storeRef = React.useRef<PanelReturnTargetStore<T> | null>(null);
23 storeRef.current ??= createPanelReturnTargetStore<T>();
24 const store = storeRef.current;
25
26 const previousResetKeyRef = React.useRef(resetKey);
27 if (previousResetKeyRef.current !== resetKey) {
28 previousResetKeyRef.current = resetKey;
29 // Render-safe silent drop: useSyncExternalStore re-reads the snapshot
30 // during this same render, so no notification is needed (or allowed).
31 store.reset();
32 }
33
34 const hasTarget = React.useSyncExternalStore(
35 store.subscribe,
36 () => store.peek() != null,
37 );
38
39 return { hasTarget, store };
40}

Callers 1

useChannelAgentSessionsFunction · 0.90

Calls 1

Tested by

no test coverage detected