ant-design/.dumi/pages/theme-editor/components/JSONEditor.tsx
5644c63219
feat: add Theme Config Editor (#39621)
* feat: add Theme Editor theme upload

* verision 2

* 移除lodash、同步当前Config

* remove export,add into devDependencies,add tool link
2022-12-27 15:16:14 +08:00

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;