Skip to content

Commit c237f4e

Browse files
committed
beautify json
1 parent 8d1a794 commit c237f4e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/components/atoms/Editor.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import 'components/atoms/Editor.css';
1111

1212
export const Editor = ({ ...props }) => {
1313
const editor = useRef();
14-
//const [code, setCode] = useState('{}');
14+
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+
}
1521

1622
const onUpdate = EditorView.updateListener.of((v) => {
1723
if (props.onChange) {
@@ -34,9 +40,11 @@ export const Editor = ({ ...props }) => {
3440
});
3541

3642
const view = new EditorView({ state, parent: editor.current });
43+
setView(view);
3744

3845
return () => {
3946
view.destroy();
47+
setView(null);
4048
};
4149
}, []);
4250

0 commit comments

Comments
 (0)