question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onChange function not called if value changes back to original value

See original GitHub issue

Description the Editor onChange prop function is called every time the value in the editor changes. Like when typing. Unless that typing leads back to the original value, from the value prop, from when the Editor was first loaded

//...
  const handleEditorChange = (value: string | undefined, event: monaco.editor.IModelContentChangedEvent) => {
    console.log('Text change')
  }
//...
  return  ( 
    <Editor
      height="100%"
      value={text}
      onMount={handleEditorDidMount}
      onChange={handleEditorChange}
    />
  )
//...

Expected behavior onChange should always be called. A change back to the original value is still a change

"@monaco-editor/react": "^4.1.3", "monaco-editor": "^0.23.0",

I understand the onChange prop is probably not called because, since the value is changed back to the original, then there “are no changes” anymore. However, I need a way to know if the value has both, been changed, and been changed back to original. With no function running for the latter -how can I tell?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
suren-atoyancommented, May 9, 2021

Hello @Seanmclem

It should be fixed, but for now either replace value with defaultValue or handle on change manually; check this

0reactions
ghostcommented, Aug 17, 2021

Hello @Seanmclem It should be fixed, but for now either replace value with defaultValue or handle on change manually; check this

switching to defaultValue worked for now. Thanks!

@Seanmclem Could you share a complete snippet of the code you ended up using. Currently encountering a similar error #278 and think it could help! Thanks for the help

Read more comments on GitHub >

github_iconTop Results From Across the Web

input onChange function not being called when value changes
What I'm asking is: is it possible to force an onChange event to fire, or preferably, have the onChange event fire when the...
Read more >
OnChange event on controls not consistent when default ...
It seems that some controls don't fire the OnChange action when the default value property is set/bound to an output from a component:....
Read more >
Value of field doesn't change if the field type is itemtype and ...
My scenario is after selecting any value in field 'A' which is of item type, I have to set/change the value of field...
Read more >
Solved: OnChange script not working as intended - ServiceNow
You will need an onLoad script to perform essentially the same functionality, as onChange will only fire when the value changes. View solution ......
Read more >
How onchange Event work in JavaScript | Examples - eduCBA
One question comes like when this change event can trigger or there is an intention to get the changed or variated value into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found