Closed alissanguyen closed 2 months ago
Thanks for the bug report @alissanguyen. Do you have a small reproduceable example or some example code?
@carbonrobot Yes, I have simplify the code a bit but here is how i'm using it.
import * as React from "react";
import Highlight, { defaultProps, Language } from "prism-react-renderer";
import editorLightTheme from "prism-react-renderer/themes/github";
import editorDarkTheme from "prism-react-renderer/themes/vsDark";
import { ContentfulCodeBlock } from "~/contentful/types";
interface Props {
data: ContentfulCodeBlock;
}
const CodeBlock: React.FC<Props> = (props) => {
const codeText = props.data.codeText;
const language: Language = props.data.language as Language ;
return (
<div className="CodeBlock__Wrapper">
<Highlight
{...defaultProps}
theme={
theme === SupportedTheme.LIGHT ? editorLightTheme : editorDarkTheme
}
code={codeText}
language={language}
>
{({ className, tokens, getLineProps, getTokenProps }) => {
return (
<div className="CodeBlock">
<pre
className={`${className} CodeBlock__InnerContainer overflow-x-auto roundedLg p-4 ${props.data.fileName ? "pt-2" : ""
}
`}
>
{tokens.map((line, i) => {
const { classname, ...restProps } = getLineProps({
line,
key: i
});
return (
<>
<div
key={i}
{...restProps}
className={`${className} LineNo__${i + 1
} grid CodeBlock__LineWrapper relative ${props.data.shouldDisplayLineNumber ? "gap-10" : ""
} breakWord whitespace-preWrap`}
>
<div>
{more JSX elements here}
</div>
</div>
</>
);
})}
</pre>
</div>
);
}}
</Highlight>
</div>
);
};
export default CodeBlock;
Update your import
import { Highlight, Language } from "prism-react-renderer";
and remove any mention of defaultProps
<Highlight
theme={
theme === SupportedTheme.LIGHT ? editorLightTheme : editorDarkTheme
}
code={codeText}
language={language}
>
Is there an existing issue for this?
Code of Conduct
Code Sandbox link
No response
Bug report