mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
Added proper cleanup functions to Form's useEffect
This commit is contained in:
parent
6550d1b8cc
commit
45d3ffcf06
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user