Skip to content

Commit 39b8e7c

Browse files
committed
refactor(ui): remove effect mount state in guest builder
1 parent 5d48ff2 commit 39b8e7c

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/components/builder/guest-builder-client.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect, useState } from "react";
3+
import { useEffect, useRef } from "react";
44
import { useResumeStore } from "@/store/resume-store";
55
import { EMPTY_RESUME_DATA, GUEST_STORAGE_KEY } from "@/lib/constants";
66
import { BuilderForm } from "./builder-form";
@@ -10,7 +10,7 @@ import { BuilderHeader } from "./builder-header";
1010
export function GuestBuilderClient() {
1111
const { setResume, data, title, templateId, fontFamily, isDirty } =
1212
useResumeStore();
13-
const [isStoreReady, setIsStoreReady] = useState(false);
13+
const isStoreReadyRef = useRef(false);
1414

1515
// Initialize store from localStorage or empty data
1616
useEffect(() => {
@@ -25,29 +25,25 @@ export function GuestBuilderClient() {
2525
parsed.fontFamily || "inter",
2626
parsed.data || EMPTY_RESUME_DATA
2727
);
28-
setIsStoreReady(true);
28+
isStoreReadyRef.current = true;
2929
return;
3030
} catch {
3131
// fall through to empty data
3232
}
3333
}
3434
setResume("guest", "My Resume", "harvard", "inter", EMPTY_RESUME_DATA);
35-
setIsStoreReady(true);
35+
isStoreReadyRef.current = true;
3636
}, [setResume]);
3737

3838
// Persist to localStorage whenever the store changes
3939
useEffect(() => {
40-
if (!isStoreReady) return;
40+
if (!isStoreReadyRef.current) return;
4141
if (!isDirty) return;
4242
localStorage.setItem(
4343
GUEST_STORAGE_KEY,
4444
JSON.stringify({ title, templateId, fontFamily, data })
4545
);
46-
}, [isStoreReady, isDirty, title, templateId, fontFamily, data]);
47-
48-
if (!isStoreReady) {
49-
return <div className="h-dvh bg-white" />;
50-
}
46+
}, [isDirty, title, templateId, fontFamily, data]);
5147

5248
return (
5349
<div className="h-dvh flex flex-col bg-white overflow-hidden">

0 commit comments

Comments
 (0)