Properly handle cleared ref after unmount

This commit is contained in:
Alexander Zinchuk 2022-05-16 13:34:00 +02:00
parent 810f2bdd65
commit 2e156d7ef4

View File

@ -29,10 +29,10 @@ const useDraft = (
const updateDraft = useCallback((draftChatId: string, draftThreadId: number) => {
const currentHtml = htmlRef.current;
if (editedMessage) return;
if (currentHtml === undefined || editedMessage) return;
if (currentHtml.length) {
saveDraft({ chatId: draftChatId, threadId: draftThreadId, draft: parseMessageInput(currentHtml!) });
} else if (currentHtml !== undefined) {
} else {
clearDraft({ chatId: draftChatId, threadId: draftThreadId });
}
}, [clearDraft, editedMessage, htmlRef, saveDraft]);