Skip to content

Commit 18535e8

Browse files
committed
Use react.memo to disable flickering
1 parent 5ae806c commit 18535e8

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

example/components/chakra-markdown.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import { Box, Text, Link as ChakraLink, Heading, useColorModeValue, useColorMode
33
import MonacoEditor from '@monaco-editor/react';
44
import ReactMarkdown from 'react-markdown';
55

6-
function ChakraMarkdown({ content }) {
7-
// Access Chakra's color mode
6+
const ChakraMarkdown = React.memo<any>(({ content }) => {
87
const { colorMode } = useColorMode();
9-
10-
// Dynamic theme for Monaco Editor based on Chakra UI color mode
118
const monacoTheme = colorMode === 'dark' ? 'vs-dark' : 'vs-light';
129

13-
// Custom renderers for Markdown components using Chakra UI and Monaco Editor for code blocks
1410
const renderers = {
1511
h1: ({ children }) => <Heading as="h1" size="xl" mb={2}>{children}</Heading>,
1612
h2: ({ children }) => <Heading as="h2" size="lg" mb={2}>{children}</Heading>,
@@ -45,6 +41,6 @@ function ChakraMarkdown({ content }) {
4541
};
4642

4743
return <ReactMarkdown components={renderers} children={content} />;
48-
}
44+
});
4945

5046
export default ChakraMarkdown;

0 commit comments

Comments
 (0)