Added proper cleanup functions to Form's useEffect

This commit is contained in:
Simon Backx 2022-07-22 17:24:02 +02:00
parent 6550d1b8cc
commit 45d3ffcf06

View File

@ -88,9 +88,11 @@ const Form = (props) => {
return;
}
let timer;
// Scroll to view if it's a reply
if (props.isReply) {
setTimeout(() => {
timer = setTimeout(() => {
if (!formEl.current) {
// Unmounted
return;
@ -119,6 +121,12 @@ const Form = (props) => {
});
})
.run();
return () => {
if (timer) {
clearTimeout(timer);
}
};
}, [editor, props]);
useEffect(() => {
@ -126,10 +134,6 @@ const Form = (props) => {
return;
}
// Remove previous events
editor.off('focus');
editor.off('blur');
editor.on('focus', () => {
onFormFocus();
});
@ -143,7 +147,13 @@ const Form = (props) => {
//props.toggle();
}
}
});
});
return () => {
// Remove previous events
editor?.off('focus');
editor?.off('blur');
};
}, [editor, props, onFormFocus]);
const submitForm = async (event) => {