Skip to content

Detecting source of change on Controlled Editor | Preventing onChange Event on programmatic value change #91

Closed
@alokg1019

Description

@alokg1019

I am using the onChange event to detect changes in the editor and call my function to process those changes. This is working fine.

Sometimes, I also set the value in the editor by using the value prop on the ControlledEditor, which in turn is controlled by the state in my component. So when the state changes, the text in the editor also updates using the value prop.
However, during this change, the onChange event is also triggered by the ControlledEditor thereby again calling my OnChange handler. I would like to detect and stop this change event from firing when I update the text in the editor programmatically using the value prop.
How can I detect and prevent the onChange event from firing when the value is changed programmatically?

I checked with a normal text field and it does not fire a change event when the value is set programmatically. The change event is fired only when the user focuses on types in the text input field.

Attaching codesandbox link to illustrate this further: https://codesandbox.io/s/monaco-editorreact---controlled-editor-2-cs717?file=/src/index.js

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions