Skip to content

Commit 4a87757

Browse files
fix ssr accessing window obj
1 parent ff21af1 commit 4a87757

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/components/private-repos-dialog.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
"use client";
2+
13
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog";
24
import { Input } from "./ui/input";
35
import { Button } from "./ui/button";
4-
import { useState } from "react";
6+
import { useState, useEffect } from "react";
57
import Link from "next/link";
68

79
interface PrivateReposDialogProps {
@@ -15,13 +17,14 @@ export function PrivateReposDialog({
1517
onClose,
1618
onSubmit,
1719
}: PrivateReposDialogProps) {
18-
const [pat, setPat] = useState(() => {
19-
// Initialize from localStorage if available
20-
if (typeof window !== "undefined") {
21-
return localStorage.getItem("github_pat") ?? "";
20+
const [pat, setPat] = useState<string>("");
21+
22+
useEffect(() => {
23+
const storedPat = localStorage.getItem("github_pat");
24+
if (storedPat) {
25+
setPat(storedPat);
2226
}
23-
return "";
24-
});
27+
}, []);
2528

2629
const handleSubmit = (e: React.FormEvent) => {
2730
e.preventDefault();

0 commit comments

Comments
 (0)