Skip to content

Commit 8c6232e

Browse files
BrettJephsonclaude
andcommitted
Avoid re-rendering every tab group on a selection change
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f6a4ffb commit 8c6232e

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

packages/gitbook/src/components/Select/useSelect.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ import { useCallback, useSyncExternalStore } from 'react';
55
import { selectStore } from '@/lib/select';
66

77
/**
8-
* Subscribe to the site-wide `select` state. Returns the current recency list plus the setters.
9-
* Consumers that only need "which of my options is active" should prefer {@link useResolvedSlug}.
8+
* Setters for the site-wide `select` state. Deliberately does not subscribe: the store notifies on
9+
* every activation anywhere on the page, so returning the recency list here would re-render every
10+
* block that only ever wanted to *write* a selection. To read one, use {@link useResolvedSlug},
11+
* which re-renders a block only when its own resolved option changes.
1012
*/
1113
export function useSelect() {
12-
const slugs = useSyncExternalStore(
13-
selectStore.subscribe,
14-
selectStore.getState,
15-
selectStore.getState
16-
).slugs;
17-
1814
return {
19-
slugs,
2015
activate: selectStore.activate,
2116
deactivate: selectStore.deactivate,
2217
};

0 commit comments

Comments
 (0)