Skip to content

Commit 0a79755

Browse files
authored
fix: error emoji text component (#2307)
Signed-off-by: Adam Setch <[email protected]>
1 parent e685d03 commit 0a79755

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/renderer/components/primitives/EmojiText.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
import { type FC, useEffect, useRef } from 'react';
22

33
import { convertTextToEmojiImgHtml } from '../../utils/emojis';
4-
54
export interface IEmojiText {
65
text: string;
76
}
8-
97
export const EmojiText: FC<IEmojiText> = ({ text }) => {
10-
const ref = useRef<HTMLDivElement>(null);
8+
const ref = useRef<HTMLDivElement | null>(null);
9+
const mountedRef = useRef(true);
1110

1211
useEffect(() => {
12+
mountedRef.current = true;
13+
1314
const updateEmojiText = async () => {
15+
const emojiHtml = await convertTextToEmojiImgHtml(text);
16+
17+
if (!mountedRef.current) {
18+
return;
19+
}
20+
1421
if (ref.current) {
15-
const emojiHtml = await convertTextToEmojiImgHtml(text);
1622
ref.current.innerHTML = emojiHtml;
1723
}
1824
};
25+
1926
updateEmojiText();
27+
28+
return () => {
29+
mountedRef.current = false;
30+
};
2031
}, [text]);
2132

2233
return <div className="text-7xl" ref={ref} />;

0 commit comments

Comments
 (0)