suren-atoyan / monaco-react

Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins

Home Page:https://monaco-react.surenatoyan.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Controlled mode doesn't work. i.e. value behaves exactly like defaultValue

ryanackley opened this issue · comments

Describe the bug
The value prop for the Editor component seems to behave exactly like defaultValue. That is the initial editor value is settable but after that, it's completely controlled by the user.

To Reproduce
Attempt to create a controlled Editor instance with value and onChange props.

See my example in codesandbox.

Expected behavior
The value of the editor should be controllable programmatically

Additional context
I was trying to create a one line editor component as described here.

Some more context. It only seems to break if value doesn't change. The bug applies more narrowly to my use-case.

As a note, we just fixed a difficult-to-track related bug - using the value prop to control the component is buggy. Instead, using the defaultValue prop works fine.

So a workaround is to use defaultValue to create a controlled component.

See also this comment which highlights that the value prop has some kind of state problem and to avoid using it.