I want to rewrite this component https://github.com/josdejong/jsoneditor/blob/master/examples/react_advanced_demo/src/JSONEditorReact.js to a functional component. I made this:
const Editor = ({json, mode, onChange}) => {
const elRef = useRef(null);
useEffect(() => {
const options = {
onChangeText: onChange,
onChangeJson: onChange,
};
const jsonEditor = new JSONEditor(elRef.current, options);
if (jsonEditor) {
if (json) {
jsonEditor.set(json);
}
if (mode) {
jsonEditor.setMode(mode);
}
}
return () => {
if (jsonEditor) {
jsonEditor.destroy();
}
}
},[json,mode]);
return (
<div
className={styles.jsoneditor_react_container}
ref={elRef}
/>
)
}
export default Editor;
My question is next: Is it correct to unmount the component jsonEditor.destroy();
inside that useEffect with [json, mode] dependancies or i should create another useEffect with empty dependancy array to get the same behaviour as in class component?