mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
site: site code style optimization (#40088)
This commit is contained in:
parent
6c21f53e35
commit
c0ce8e5455
@ -1,33 +1,30 @@
|
|||||||
import { JSONEditor as Editor, Mode, type JSONEditorPropsOptional } from 'vanilla-jsoneditor';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import React from 'react';
|
import { JSONEditor, Mode } from 'vanilla-jsoneditor';
|
||||||
|
import type { JSONEditorPropsOptional } from 'vanilla-jsoneditor';
|
||||||
|
|
||||||
const JSONEditor = (props: JSONEditorPropsOptional) => {
|
const Editor: React.FC<JSONEditorPropsOptional> = (props) => {
|
||||||
const refContainer = React.useRef(null);
|
const editorRef = useRef<JSONEditor>(null);
|
||||||
const refEditor = React.useRef(null);
|
const container = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
refEditor.current = new Editor({
|
editorRef.current = new JSONEditor({
|
||||||
target: refContainer.current,
|
target: container.current,
|
||||||
props: {
|
props: { mode: Mode.text },
|
||||||
mode: Mode.text,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (refEditor.current) {
|
if (editorRef.current) {
|
||||||
refEditor.current.destroy();
|
editorRef.current.destroy();
|
||||||
refEditor.current = null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
if (refEditor.current) {
|
if (editorRef.current) {
|
||||||
refEditor.current.updateProps(props);
|
editorRef.current.updateProps(props);
|
||||||
}
|
}
|
||||||
}, [props]);
|
}, [props]);
|
||||||
|
|
||||||
return <div className="vanilla-jsoneditor-react" ref={refContainer} />;
|
return <div ref={container} className="vanilla-jsoneditor-react" />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default JSONEditor;
|
export default Editor;
|
||||||
|
Loading…
Reference in New Issue
Block a user