2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

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();
});
@ -144,6 +148,12 @@ const Form = (props) => {
}
}
});
return () => {
// Remove previous events
editor?.off('focus');
editor?.off('blur');
};
}, [editor, props, onFormFocus]);
const submitForm = async (event) => {