Edit: I used @monaco-editor/react for my app.
The problem is about, in my nextJS app I used onDidChangeCursorPosition event in Monaco Editor react to do some calculations. Now I need a lock button to stop doing those calculations. the dispose() method works from first place, but after onDidChangeCursorPosition did happened once, dispose() cannot stop the event anymore. I got confused about this problem and unfortunately there are not much resources to look after it. here is my code:
const [locked, setLocked] = React.useState(false);
if(!locked){
editorRef?.current?.onDidChangeCursorPosition(handleCursorPositionChange);
} else {
editorRef?.current?.onDidChangeCursorPosition(handleCursorPositionChange).dispose();
}
return(
<Button onClick={()=>setLocked(true)}>Lock</Button>
)
Here handleCursorPositionChange is a big function to do some calculations, but even I tested a simple console.log, it's still won't dispose the event.