44* ------------------------------------------------------------------------------------------ */
55
66import * as monaco from '@codingame/monaco-vscode-editor-api' ;
7- import React , { CSSProperties , useCallback , useEffect , useRef , useState } from 'react' ;
7+ import React , { CSSProperties , useCallback , useEffect , useRef } from 'react' ;
88import { didModelContentChange , MonacoEditorLanguageClientWrapper , TextChanges , TextModels , WrapperConfig } from 'monaco-editor-wrapper' ;
99
1010export type MonacoEditorProps = {
@@ -29,7 +29,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
2929
3030 const wrapperRef = useRef < MonacoEditorLanguageClientWrapper > ( new MonacoEditorLanguageClientWrapper ( ) ) ;
3131 const containerRef = useRef < HTMLDivElement > ( null ) ;
32- const [ onTextChangedSubscriptions , setOnTextChangedSubscriptions ] = useState < monaco . IDisposable [ ] > ( [ ] ) ;
32+ const onTextChangedSubscriptions = useRef < monaco . IDisposable [ ] > ( [ ] ) ;
3333
3434 useEffect ( ( ) => {
3535 return ( ) => {
@@ -95,7 +95,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
9595 didModelContentChange ( textModels , wrapperConfig . editorAppConfig ?. codeResources , onTextChanged ) ;
9696 } ) ) ;
9797 }
98- setOnTextChangedSubscriptions ( newSubscriptions ) ;
98+ onTextChangedSubscriptions . current = newSubscriptions ;
9999 // do it initially
100100 didModelContentChange ( textModels , wrapperConfig . editorAppConfig ?. codeResources , onTextChanged ) ;
101101 }
@@ -137,10 +137,10 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
137137 } , [ ] ) ;
138138
139139 const disposeOnTextChanged = useCallback ( ( ) => {
140- for ( const subscription of onTextChangedSubscriptions ) {
140+ for ( const subscription of onTextChangedSubscriptions . current ) {
141141 subscription . dispose ( ) ;
142142 }
143- setOnTextChangedSubscriptions ( [ ] ) ;
143+ onTextChangedSubscriptions . current = [ ] ;
144144 } , [ ] ) ;
145145
146146 return (
0 commit comments