ant-design/.dumi/theme/common/JSONEditor/index.tsx

31 lines
805 B
TypeScript
Raw Normal View History

import React, { useEffect, useRef } from 'react';
2024-12-04 23:56:09 +08:00
import type { JsonEditor, JSONEditorPropsOptional } from 'vanilla-jsoneditor';
import { createJSONEditor, Mode } from 'vanilla-jsoneditor';
const Editor: React.FC<JSONEditorPropsOptional> = (props) => {
2024-12-04 23:56:09 +08:00
const editorRef = useRef<JsonEditor>();
const container = useRef<HTMLDivElement>(null);
useEffect(() => {
2024-12-04 23:56:09 +08:00
if (container.current) {
editorRef.current = createJSONEditor({
target: container.current,
props: {
mode: Mode.text,
},
});
}
return () => {
editorRef.current?.destroy();
};
}, []);
useEffect(() => {
editorRef.current?.updateProps(props);
}, [props.content]);
return <div ref={container} className="vanilla-jsoneditor-react" />;
};
export default Editor;