ant-design/.dumi/theme/common/JSONEditor/index.tsx
MadCcc f8dfdd0c96
docs: fix prerender (#39864)
* docs: fix prerender

* chore: add fallback

* chore: update spin

* chore: code clean
2022-12-28 18:17:17 +08:00

34 lines
794 B
TypeScript

import { JSONEditor as Editor, Mode, type JSONEditorPropsOptional } from 'vanilla-jsoneditor';
import React from 'react';
const JSONEditor = (props: JSONEditorPropsOptional) => {
const refContainer = React.useRef(null);
const refEditor = React.useRef(null);
React.useEffect(() => {
refEditor.current = new Editor({
target: refContainer.current,
props: {
mode: Mode.text,
},
});
return () => {
if (refEditor.current) {
refEditor.current.destroy();
refEditor.current = null;
}
};
}, []);
React.useEffect(() => {
if (refEditor.current) {
refEditor.current.updateProps(props);
}
}, [props]);
return <div className="vanilla-jsoneditor-react" ref={refContainer} />;
};
export default JSONEditor;