Skip to content

Commit 53e2823

Browse files
committed
Index returns hookinfo | undefined.
1 parent 024c0c8 commit 53e2823

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

docs/src/components/sdk/hook-documentation.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,32 +446,43 @@ export function HookFromJson({ hookName }: { hookName: string }) {
446446
const [error, setError] = React.useState<string | null>(null);
447447

448448
React.useEffect(() => {
449+
const controller = new AbortController();
450+
449451
async function loadHookInfo() {
450-
try {
451-
setLoading(true);
452-
setError(null);
452+
setLoading(true);
453+
setError(null);
453454

454-
// Load the hooks.json file
455-
const response = await fetch('/sdk-docs/hooks.json');
455+
try {
456+
const response = await fetch('/sdk-docs/hooks.json', { signal: controller.signal });
456457
if (!response.ok) {
457458
throw new Error(`Failed to load hooks.json: ${response.statusText}`);
458459
}
459460

460-
const hooksData = await response.json();
461+
const hooksData: Partial<Record<string, HookInfo>> = await response.json();
461462
const foundHook = hooksData[hookName];
462463

463464
if (!foundHook) {
464-
throw new Error(`Hook "${hookName}" not found in hooks.json. Available hooks: ${Object.keys(hooksData).join(', ')}`);
465+
const availableKeys = Object.keys(hooksData);
466+
const preview = availableKeys.slice(0, 10).join(', ');
467+
const suffix = availableKeys.length > 10 ? `, ... (${availableKeys.length} total)` : '';
468+
throw new Error(`Hook "${hookName}" not found in hooks.json. Available hooks: ${preview}${suffix}`);
465469
}
466470

467-
setHookInfo(foundHook);
471+
if (!controller.signal.aborted) {
472+
setHookInfo(foundHook);
473+
}
468474
} catch (err) {
475+
if (controller.signal.aborted) return;
469476
setError(err instanceof Error ? err.message : 'Unknown error');
470477
} finally {
471-
setLoading(false);
478+
if (!controller.signal.aborted) {
479+
setLoading(false);
480+
}
472481
}
473482
}
474483
runAsynchronously(loadHookInfo());
484+
485+
return () => controller.abort();
475486
}, [hookName]);
476487

477488
if (loading) {

0 commit comments

Comments
 (0)