UNPKG

@chakra-ui/react

Version:

Responsive and accessible React UI components built with React and Emotion

31 lines (27 loc) 647 B
"use strict"; 'use strict'; var React = require('react'); function useCodeHighlight(props) { const { loadContext, getHighlighter, unloadContext } = props; const [context, setContext] = React.useState(null); const highlight = React.useMemo( () => getHighlighter(context), [getHighlighter, context] ); React.useEffect(() => { let ctx = null; loadContext?.().then((c) => { ctx = c; setContext(c); }); return () => { unloadContext?.(ctx); }; }, [loadContext, unloadContext]); return { highlight, loadContext, getHighlighter }; } exports.useCodeHighlight = useCodeHighlight;