Skip to content

Commit 93156cb

Browse files
committed
Fix stale code group selection fallback
1 parent 58876a3 commit 93156cb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/components/src/components/code-group/code-group-select.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ const CodeGroupSelect = ({
4444
}: CodeGroupSelectProps) => {
4545
const groups = Object.keys(snippets);
4646
const [selectedGroup, setSelectedGroup] = useState(groups[0]);
47+
const safeSelectedGroup =
48+
selectedGroup && groups.includes(selectedGroup) ? selectedGroup : groups[0];
4749

4850
const groupSnippets =
49-
selectedGroup !== undefined ? snippets[selectedGroup] : undefined;
51+
safeSelectedGroup !== undefined ? snippets[safeSelectedGroup] : undefined;
5052
const options = useMemo(
5153
() => (groupSnippets ? Object.keys(groupSnippets) : undefined),
5254
[groupSnippets]
@@ -113,7 +115,7 @@ const CodeGroupSelect = ({
113115
<CodeSelectDropdown
114116
codeBlockTheme={codeBlockTheme}
115117
options={groups}
116-
selectedOption={selectedGroup}
118+
selectedOption={safeSelectedGroup}
117119
setSelectedOption={handleGroupSelect}
118120
/>
119121
<div className="flex overflow-hidden">

0 commit comments

Comments
 (0)