Create useCodeHighlighter.tsx

This commit is contained in:
Nate Kelley 2025-07-28 14:44:35 -06:00
parent 8d3a38db60
commit 42b9f0f0e8
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
import { useEffect, useState } from 'react';
import { getHighlightedCode } from './shiki-instance';
import { useAsyncEffect } from '@/hooks';
export const useCodeHighlighter = (code: string, language: 'sql' | 'yaml') => {
const [highlightedCode, setHighlightedCode] = useState(code);
useAsyncEffect(async () => {
const highlighter = await getHighlightedCode(code, language, 'github-light');
setHighlightedCode(highlighter);
return () => {
//
};
}, [code, language]);
return highlightedCode;
};