We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8d1a794 commit c237f4eCopy full SHA for c237f4e
1 file changed
src/components/atoms/Editor.js
@@ -11,7 +11,13 @@ import 'components/atoms/Editor.css';
11
12
export const Editor = ({ ...props }) => {
13
const editor = useRef();
14
- //const [code, setCode] = useState('{}');
+ const [view, setView] = useState(null);
15
+
16
+ if (view) {
17
+ if (props.value != view.state.doc.toString()) {
18
+ view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: props.value } });
19
+ }
20
21
22
const onUpdate = EditorView.updateListener.of((v) => {
23
if (props.onChange) {
@@ -34,9 +40,11 @@ export const Editor = ({ ...props }) => {
34
40
});
35
41
36
42
const view = new EditorView({ state, parent: editor.current });
43
+ setView(view);
37
44
38
45
return () => {
39
46
view.destroy();
47
+ setView(null);
48
};
49
}, []);
50
0 commit comments