admin管理员组文章数量:1290957
I'm using React Markdown in order to render text combined with a typing effect. Because of the typing effect it is re-rendering the whole text on each letter addition and this is causing performance issues.
const MathJaxRenderer: FC<{ text: string }> = memo(({ text }) => {
return (
<MathJax>
<ReactMarkdown
remarkPlugins={[remarkGfm]}
components={{
p: ({children}) => (
<p style={{ margin: '1em 0' }}>
{children}
</p>
),
code: ({children, inline}) => {
if (inline) {
return <span>{children}</span>;
}
return (
<div style={{ margin: '1em 0' }}>
{children}
</div>
);
}
}}
>
{text}
</ReactMarkdown>
</MathJax>
);
const typeNextChar = () => {
if (charIndex < fullText.length && fullText[charIndex + 1]) {
setChatMessages(prevState => {
const updatedMessages = [...prevState];
const currentMessage = updatedMessages[index];
if (currentMessage) {
const currentDisplayText = currentMessage.displayText || '';
currentMessage.displayText = currentDisplayText + fullText[charIndex];
charIndex++;
}
return updatedMessages;
});
requestAnimationFrame(typeNextChar);
} else {
setChatMessages(prevState => {
const updatedMessages = [...prevState];
if (updatedMessages[index]) {
updatedMessages[index].isTyping = false;
}
return updatedMessages;
});
}
};
typeNextChar();
};
Is there a way to improve this? Thanks in advance.
本文标签: reactjsReact Markdown and MathJax with typing effect causing performance issuesStack Overflow
版权声明:本文标题:reactjs - React Markdown and MathJax with typing effect causing performance issues - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505663a2382304.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论