mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +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 from 'react';
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { JSONEditor, Mode } from 'vanilla-jsoneditor';
|
||||
import type { JSONEditorPropsOptional } from 'vanilla-jsoneditor';
|
||||
|
||||
const JSONEditor = (props: JSONEditorPropsOptional) => {
|
||||
const refContainer = React.useRef(null);
|
||||
const refEditor = React.useRef(null);
|
||||
const Editor: React.FC<JSONEditorPropsOptional> = (props) => {
|
||||
const editorRef = useRef<JSONEditor>(null);
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
|
||||
React.useEffect(() => {
|
||||
refEditor.current = new Editor({
|
||||
target: refContainer.current,
|
||||
props: {
|
||||
mode: Mode.text,
|
||||
},
|
||||
useEffect(() => {
|
||||
editorRef.current = new JSONEditor({
|
||||
target: container.current,
|
||||
props: { mode: Mode.text },
|
||||
});
|
||||
|
||||
return () => {
|
||||
if (refEditor.current) {
|
||||
refEditor.current.destroy();
|
||||
refEditor.current = null;
|
||||
if (editorRef.current) {
|
||||
editorRef.current.destroy();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (refEditor.current) {
|
||||
refEditor.current.updateProps(props);
|
||||
useEffect(() => {
|
||||
if (editorRef.current) {
|
||||
editorRef.current.updateProps(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