Skip to content

Commit d1d655e

Browse files
MelvinBotPujan92
andcommitted
Move empty-check condition inside useEffect body
Move the reportLastReadTime empty check from the dependency array into the effect body, so it skips the update when lastReadTime is empty rather than using a derived dependency value. Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
1 parent aaecf4c commit d1d655e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,15 @@ function ReportActionsList({
259259
*/
260260
const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime);
261261
useEffect(() => {
262+
// When lastReadTime is empty (e.g. data hasn't loaded yet after sign-in),
263+
// skip the update so we don't place the marker at the wrong position.
264+
if (reportLastReadTime === '') {
265+
return;
266+
}
262267
setUnreadMarkerTime(reportLastReadTime);
263268

264269
// eslint-disable-next-line react-hooks/exhaustive-deps
265-
}, [report.reportID, reportLastReadTime === '' ? 'empty' : 'populated']);
270+
}, [report.reportID, reportLastReadTime]);
266271

267272
const prevUnreadMarkerReportActionID = useRef<string | null>(null);
268273

0 commit comments

Comments
 (0)