File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
src/renderer/components/primitives Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 11import { type FC , useEffect , useRef } from 'react' ;
22
33import { convertTextToEmojiImgHtml } from '../../utils/emojis' ;
4-
54export interface IEmojiText {
65 text : string ;
76}
8-
97export 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 } /> ;
You can’t perform that action at this time.
0 commit comments