mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 07:09:55 +08:00
f8dfdd0c96
* docs: fix prerender * chore: add fallback * chore: update spin * chore: code clean
34 lines
794 B
TypeScript
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;
|