mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 17:19:11 +08:00
130c22ab03
* style: Code style optimization * add * rename * rename * revert * revert * revert * add
27 lines
719 B
TypeScript
27 lines
719 B
TypeScript
import React, { useEffect, useRef } from 'react';
|
|
import { JSONEditor, Mode } from 'vanilla-jsoneditor';
|
|
import type { JSONEditorPropsOptional } from 'vanilla-jsoneditor';
|
|
|
|
const Editor: React.FC<JSONEditorPropsOptional> = (props) => {
|
|
const editorRef = useRef<JSONEditor>(null);
|
|
const container = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
editorRef.current = new JSONEditor({
|
|
target: container.current,
|
|
props: { mode: Mode.text },
|
|
});
|
|
return () => {
|
|
editorRef.current?.destroy();
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
editorRef.current?.updateProps(props);
|
|
}, [props]);
|
|
|
|
return <div ref={container} className="vanilla-jsoneditor-react" />;
|
|
};
|
|
|
|
export default Editor;
|