in website/src/theme/CodeSnippet/index.js [8:55]
function CodeSnippet(props) {
const {
siteConfig: {
themeConfig: { prism = {} },
},
} = useDocusaurusContext();
const [mounted, setMounted] = useState(false);
// The Prism theme on SSR is always the default theme but the site theme
// can be in a different mode. React hydration doesn't update DOM styles
// that come from SSR. Hence force a re-render after mounting to apply the
// current relevant styles. There will be a flash seen of the original
// styles seen using this current approach but that's probably ok. Fixing
// the flash will require changing the theming approach and is not worth it
// at this point.
useEffect(() => {
setMounted(true);
}, []);
const { isDarkTheme } = useThemeContext();
const lightModeTheme = prism.theme;
const darkModeTheme = prism.darkTheme || lightModeTheme;
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
const { language = "python", code } = props;
return (
<Highlight
{...defaultProps}
code={code}
language={language}
key={mounted}
theme={prismTheme}
>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<pre className={`${className} ${styles.code}`} style={style}>
{tokens.map((line, i) => (
<div {...getLineProps({ line, key: i })}>
{line.map((token, key) => (
<span {...getTokenProps({ token, key })} />
))}
</div>
))}
</pre>
)}
</Highlight>
);
}