mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 15:19:58 +08:00
5644c63219
* feat: add Theme Editor theme upload * verision 2 * 移除lodash、同步当前Config * remove export,add into devDependencies,add tool link
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;
|