@@ -76,6 +76,7 @@ import { StripMarksOnImagePlugin } from './pmPlugins/StripMarksOnImagePlugin';
7676import { ShortcutPlugin } from './pmPlugins/ShortcutPlugin' ;
7777import { returnKeyTypeToEnterKeyHint } from './returnKeyTypeToEnterKeyHint' ;
7878import { AutolinkPlugin } from './pmPlugins/AutolinkPlugin' ;
79+ import { useStableRef } from './useStableRef' ;
7980
8081function runFocused (
8182 editor : Editor ,
@@ -126,56 +127,26 @@ export const EnrichedTextInput = ({
126127 ( ) => mergeWithDefaultHtmlStyle ( htmlStyle ) ,
127128 [ htmlStyle ]
128129 ) ;
129-
130- const htmlStyleRef = useRef ( resolvedHtmlStyle ) ;
131- useEffect ( ( ) => {
132- htmlStyleRef . current = resolvedHtmlStyle ;
133- } , [ resolvedHtmlStyle ] ) ;
134-
135- const onPasteImagesRef = useRef ( onPasteImages ) ;
136- useEffect ( ( ) => {
137- onPasteImagesRef . current = onPasteImages ;
138- } , [ onPasteImages ] ) ;
139-
140- const mentionIndicatorsRef = useRef ( mentionIndicators ) ;
141- useEffect ( ( ) => {
142- mentionIndicatorsRef . current = mentionIndicators ;
143- } , [ mentionIndicators ] ) ;
144-
145- const mentionCallbacksRef = useRef ( {
146- onStartMention,
147- onChangeMention,
148- onEndMention,
149- onMentionDetected,
150- } ) ;
151- useEffect ( ( ) => {
152- mentionCallbacksRef . current = {
130+ const mentionCallbacks = useMemo (
131+ ( ) => ( {
153132 onStartMention,
154133 onChangeMention,
155134 onEndMention,
156135 onMentionDetected,
157- } ;
158- } , [ onStartMention , onChangeMention , onEndMention , onMentionDetected ] ) ;
159-
160- const submitBehaviorRef = useRef ( submitBehavior ) ;
161- const onSubmitEditingRef = useRef ( onSubmitEditing ) ;
162- const onKeyPressRef = useRef ( onKeyPress ) ;
163- const editorInstanceRef = useRef < Editor | null > ( null ) ;
136+ } ) ,
137+ [ onStartMention , onChangeMention , onEndMention , onMentionDetected ]
138+ ) ;
164139
165- useEffect ( ( ) => {
166- submitBehaviorRef . current = submitBehavior ;
167- } , [ submitBehavior ] ) ;
168- useEffect ( ( ) => {
169- onSubmitEditingRef . current = onSubmitEditing ;
170- } , [ onSubmitEditing ] ) ;
171- useEffect ( ( ) => {
172- onKeyPressRef . current = onKeyPress ;
173- } , [ onKeyPress ] ) ;
140+ const htmlStyleRef = useStableRef ( resolvedHtmlStyle ) ;
141+ const onPasteImagesRef = useStableRef ( onPasteImages ) ;
142+ const mentionIndicatorsRef = useStableRef ( mentionIndicators ) ;
143+ const submitBehaviorRef = useStableRef ( submitBehavior ) ;
144+ const onSubmitEditingRef = useStableRef ( onSubmitEditing ) ;
145+ const onKeyPressRef = useStableRef ( onKeyPress ) ;
146+ const useHtmlNormalizerRef = useStableRef ( useHtmlNormalizer ) ;
147+ const mentionCallbacksRef = useStableRef ( mentionCallbacks ) ;
174148
175- const useHtmlNormalizerRef = useRef ( useHtmlNormalizer ) ;
176- useEffect ( ( ) => {
177- useHtmlNormalizerRef . current = useHtmlNormalizer ;
178- } , [ useHtmlNormalizer ] ) ;
149+ const editorInstanceRef = useRef < Editor | null > ( null ) ;
179150
180151 const handleKeyDown = ( doc : Node , event : KeyboardEvent ) : boolean => {
181152 onKeyPressRef . current ?.( adaptWebToNativeEvent ( event , { key : event . key } ) ) ;
@@ -252,7 +223,7 @@ export const EnrichedTextInput = ({
252223 showOnlyWhenEditable : true ,
253224 } ) ,
254225 ] ,
255- [ placeholder ]
226+ [ placeholder , htmlStyleRef , mentionIndicatorsRef ]
256227 ) ;
257228
258229 const editor = useEditor (
@@ -324,7 +295,7 @@ export const EnrichedTextInput = ({
324295 useEffect ( ( ) => {
325296 if ( ! editor ) return ;
326297 return subscribeMentionEvents ( editor , ( ) => mentionCallbacksRef . current ) ;
327- } , [ editor ] ) ;
298+ } , [ editor , mentionCallbacksRef ] ) ;
328299
329300 useOnChangeHtml ( editor , onChangeHtml ) ;
330301 useOnChangeText ( editor , onChangeText ) ;
@@ -388,7 +359,7 @@ export const EnrichedTextInput = ({
388359 setNativeProps : ( ) => { } ,
389360 setTextAlignment : ( ) => { } ,
390361 } ) ,
391- [ editor ]
362+ [ editor , mentionIndicatorsRef , useHtmlNormalizerRef ]
392363 ) ;
393364
394365 const editorStyle : CSSProperties = useMemo (
0 commit comments