perf: abort

This commit is contained in:
archer
2023-07-18 15:20:58 +08:00
parent 8a25aeabc4
commit 2330186a09
8 changed files with 50 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import ReactMarkdown from 'react-markdown';
import RemarkGfm from 'remark-gfm';
import RemarkMath from 'remark-math';
@@ -48,13 +48,16 @@ const Markdown = ({
isChatting?: boolean;
onClick?: (e: any) => void;
}) => {
const components = useRef({
a: Link,
img: Image,
pre: 'div',
p: 'div',
code: (props: any) => <Code {...props} onClick={onClick} />
});
const components = useMemo(
() => ({
a: Link,
img: Image,
pre: 'div',
p: 'div',
code: (props: any) => <Code {...props} onClick={onClick} />
}),
[onClick]
);
return (
<ReactMarkdown
@@ -64,7 +67,7 @@ const Markdown = ({
remarkPlugins={[RemarkGfm, RemarkMath, RemarkBreaks]}
rehypePlugins={[RehypeKatex]}
// @ts-ignore
components={components.current}
components={components}
>
{source}
</ReactMarkdown>