{"id":25695643,"url":"https://github.com/abhub23/react-flip-game","last_synced_at":"2026-04-29T23:05:56.834Z","repository":{"id":269210369,"uuid":"906730386","full_name":"abhub23/React-Flip-Game","owner":"abhub23","description":"Just a Memory game","archived":false,"fork":false,"pushed_at":"2025-09-29T03:28:00.000Z","size":237,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-29T05:31:48.794Z","etag":null,"topics":["grid-layout","reactgame","reactjs"],"latest_commit_sha":null,"homepage":"https://flipgame.abdullahtech.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhub23.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-21T18:27:25.000Z","updated_at":"2025-09-29T03:28:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"33cc1c9b-0f76-4119-9091-8d7e485d5b2e","html_url":"https://github.com/abhub23/React-Flip-Game","commit_stats":null,"previous_names":["abhub23/react-flip-game"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abhub23/React-Flip-Game","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhub23%2FReact-Flip-Game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhub23%2FReact-Flip-Game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhub23%2FReact-Flip-Game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhub23%2FReact-Flip-Game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhub23","download_url":"https://codeload.github.com/abhub23/React-Flip-Game/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhub23%2FReact-Flip-Game/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020905,"owners_count":26086948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grid-layout","reactgame","reactjs"],"created_at":"2025-02-25T00:52:14.769Z","updated_at":"2025-10-14T20:32:54.019Z","avatar_url":"https://github.com/abhub23.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zustand State and `set` Explained\n\n## 1. Ways to Update State Using `set`\nZustand provides two ways to update state inside the store:\n\n### a) Functional Update (`set((state) =\u003e {...})`)\n- Use this **when your update depends on the previous state**.\n- It ensures that you always modify the latest state.\n\n```ts\nset((state) =\u003e ({ count: state.count + 1 }));\n```\n\n\u003e **Why?** The function receives `state`, so we can safely modify `count` based on the latest state.\n\n---\n\n### b) Direct Object Update (`set({...})`)\n- Use this when updating state **without depending on the previous state**.\n\n```ts\nset({ user: newUser });\n```\n\n\u003e **Why?** We don’t need the previous state here, just replacing `user`.\n\n---\n\n## 2. Parentheses in `set((state) =\u003e {...})`\n- When returning an object in an **arrow function**, **wrap it in `()`** to avoid JavaScript confusion.\n\n✅ **Correct:**\n```ts\nset((state) =\u003e ({ count: state.count + 1 })); // ✅ Parentheses required\n```\n\n❌ **Incorrect (No `return`, JavaScript thinks `{}` is a function block)**\n```ts\nset((state) =\u003e { count: state.count + 1 }); // ❌ Syntax error!\n```\n\nIf using a function block `{}`, explicitly use `return`:\n```ts\nset((state) =\u003e {\n  return { count: state.count + 1 };\n});\n```\n\n---\n\n## 3. When to Use Which?\n| **Approach** | **When to Use?** | **Example** |\n|-------------|----------------|-----------|\n| `set((state) =\u003e ({ ... }))` | If updating based on previous state | `set((state) =\u003e ({ count: state.count + 1 }))` |\n| `set({ ... })` | If replacing state without needing the old state | `set({ user: newUser })` |\n\n---\n\n## 4. Why No Parentheses in Some Cases?\n- If an arrow function uses `{}`, it’s treated as a function **block** and requires an explicit `return`.\n- If it’s **one line returning an object**, wrap it in `()`.\n\n✅ **With `{}` (Needs `return`)**\n```ts\nset((theme) =\u003e {\n  const toggle = theme.isDarkmode === \"dark\" ? \"light\" : \"dark\";\n  localStorage.setItem(\"theme\", toggle);\n  return { isDarkmode: toggle }; // ✅ Explicit return needed\n});\n```\n\n✅ **With `()` (Implicit Return)**\n```ts\nset((state) =\u003e ({ count: state.count + 1 })); // ✅ No `return` needed\n```\n\n---\n\n## Summary\n- Use `set((state) =\u003e ({ ... }))` when updating based on previous state, and `set({ ... })` when setting a new value directly.\n- Use `()` around objects when using an **implicit return** in arrow functions.\n- If using `{}`, you **must** use `return`.\n\n---\n\n🚀 **Now you have a complete reference for Zustand state updates!**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhub23%2Freact-flip-game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhub23%2Freact-flip-game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhub23%2Freact-flip-game/lists"}