@@ -227,11 +227,14 @@ export const CodeEditor = ({
227227} : CodeEditorProps ) => {
228228 const parent = useRef < any > ( undefined ) ;
229229 const [ view , setView ] = React . useState < EditorView | undefined > ( ) ;
230- const currentView = React . useRef < EditorView > ( ) ;
231- currentView . current = view ;
232- const currentReadOnly = React . useRef ( readOnly ) ;
233- currentReadOnly . current = readOnly ;
234- //const currentDisabled = React.useRef(disabled);
230+ const currentView = React . useRef < EditorView > ( )
231+ currentView . current = view
232+ const currentReadOnly = React . useRef ( readOnly )
233+ currentReadOnly . current = readOnly
234+ const currentOnChange = React . useRef ( onChange )
235+ currentOnChange . current = onChange
236+ const currentDisabled = React . useRef ( disabled )
237+ currentDisabled . current = disabled
235238 const [ showPreview , setShowPreview ] = React . useState < boolean > ( false ) ;
236239 // CodeMirror Compartments in order to allow for re-configuration after initialization
237240 const readOnlyCompartment = React . useRef < Compartment > ( compartment ( ) )
@@ -320,11 +323,11 @@ export const CodeEditor = ({
320323 disabledCompartment . current . of ( EditorView ?. editable . of ( ! disabled ) ) ,
321324 AdaptedEditorViewDomEventHandlers ( domEventHandlers ) as Extension ,
322325 EditorView ?. updateListener . of ( ( v : ViewUpdate ) => {
323- if ( disabled ) return ;
326+ if ( currentDisabled . current ) return ;
324327
325- if ( onChange && v . docChanged ) {
328+ if ( currentOnChange . current && v . docChanged ) {
326329 // Only fire if the text has actually been changed
327- onChange ( v . state . doc . toString ( ) ) ;
330+ currentOnChange . current ( v . state . doc . toString ( ) ) ;
328331 }
329332
330333 if ( onSelection )
0 commit comments