mirror of https://github.com/buster-so/buster.git
Create useCodeHighlighter.tsx
This commit is contained in:
parent
8d3a38db60
commit
42b9f0f0e8
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue