Skip to content

Commit

Permalink
chore : zustand_setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrobin committed Jul 8, 2024
1 parent 270e838 commit 41efbaa
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
46 changes: 42 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"@vercel/postgres": "^0.8.0",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"zustand": "^4.5.4"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
14 changes: 10 additions & 4 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Image from "next/image";
import chevLeft from "../../public/chevron-left.svg";
import chevRight from "../../public/chevron-right.svg";
import Link from "next/link";
import IdStore from "./store";

interface Word {
content: string;
Expand All @@ -28,10 +29,18 @@ export default function Home() {
const [inputCollection, setInputCollection] = useState<string[]>([]);
const [quoteNumber, setQuoteNumber] = useState<number>(0);
const [quote, setQuote] = useState<QUOTE>(quotes[0]);
const [userName, setUserName] = useState("");
const { id, setId } = IdStore();
const testName = "test";

useEffect(() => {
setTextValue("");
setQuote(quotes[quoteNumber]);
}, [quoteNumber]);
setId(testName);
setUserName(id);
}, [quoteNumber, id, setId]);

console.log(userName);

const sentences = quote.content.split("\n");

Expand Down Expand Up @@ -138,15 +147,12 @@ export default function Home() {
};

const handleNextClick = () => {
console.log("clicked");
if (quoteNumber + 1 >= quotes.length) {
setQuoteNumber(0);
} else setQuoteNumber((prev) => ++prev);
setQuote(quotes[quoteNumber]);
};
console.log(quotes.length);
const handlePrevClick = () => {
console.log("clicked");
if (quoteNumber <= 0) {
setQuoteNumber(quotes.length - 1);
} else setQuoteNumber((prev) => --prev);
Expand Down
16 changes: 16 additions & 0 deletions src/app/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { create } from "zustand";

// 초기 상태 정의
interface ID {
id: string;
setId: (id: string) => void;
}

const IdStore = create<ID>((set) => ({
id: "init",
setId: (id) => {
set(() => ({ id: id }));
},
}));

export default IdStore;

0 comments on commit 41efbaa

Please sign in to comment.