From 75b76d7747b7ebca3a05ff6591f49288f6f9a5dc Mon Sep 17 00:00:00 2001 From: thecodrr Date: Tue, 7 Jun 2022 06:17:09 +0500 Subject: [PATCH] fix: title does not empty sometimes on new notes --- apps/web/src/components/editor/title-box.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx index 20be81b4b..1a10738f7 100644 --- a/apps/web/src/components/editor/title-box.tsx +++ b/apps/web/src/components/editor/title-box.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { Input } from "@rebass/forms"; import { useStore, store, SESSION_STATES } from "../../stores/editor-store"; @@ -18,16 +18,19 @@ function TitleBox(props: TitleBoxProps) { const [placeholder, setPlaceholder] = useState(); useEffect(() => { - if (state === SESSION_STATES.new) { + const noteTitle = store.get().session.title; + if (state === SESSION_STATES.new && noteTitle !== currentTitle) { setCurrentTitle(""); setPlaceholder(""); } else if (state === SESSION_STATES.stale) { - setCurrentTitle(store.get().session.title); + setCurrentTitle(noteTitle); } - }, [state]); + // We do not want to update when currentTitle changes. + }, [state, sessionId]); useEffect(() => { - setPlaceholder(title); + if (currentTitle !== title) setPlaceholder(title); + // We do not want to update when currentTitle changes. }, [title]); return (