{"id":23219141,"url":"https://github.com/fizzyelt/custom-jotai-query-poc","last_synced_at":"2025-04-05T14:42:47.836Z","repository":{"id":213495078,"uuid":"734250397","full_name":"FizzyElt/custom-jotai-query-POC","owner":"FizzyElt","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-26T15:07:56.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T11:39:10.003Z","etag":null,"topics":["jotai","react","react-query"],"latest_commit_sha":null,"homepage":"https://sprightly-alpaca-553a7d.netlify.app/","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/FizzyElt.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}},"created_at":"2023-12-21T08:20:14.000Z","updated_at":"2023-12-21T15:27:07.000Z","dependencies_parsed_at":"2023-12-26T16:59:31.205Z","dependency_job_id":null,"html_url":"https://github.com/FizzyElt/custom-jotai-query-POC","commit_stats":null,"previous_names":["fizzyelt/custom-jotai-query-poc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyElt%2Fcustom-jotai-query-POC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyElt%2Fcustom-jotai-query-POC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyElt%2Fcustom-jotai-query-POC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FizzyElt%2Fcustom-jotai-query-POC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FizzyElt","download_url":"https://codeload.github.com/FizzyElt/custom-jotai-query-POC/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353679,"owners_count":20925325,"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","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":["jotai","react","react-query"],"created_at":"2024-12-18T21:19:51.812Z","updated_at":"2025-04-05T14:42:47.814Z","avatar_url":"https://github.com/FizzyElt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom simple jotai query\n\n## 功能/行為\n\n- 在發出第一次 fetch 之前，任何 key change、invalidate 都不會重新觸發 refetch\n- 連續的觸發 refetch 狀態只會取最後一個結果更新狀態(但一樣會發出多次)\n- 沒有任何 cache 機制\n- 多種不同 key 不會有多分資料同時存在\n- 不會失敗自動重發\n- 資料存放在哪取決於 atom 在哪個 scope (都沒放就會一直存在 global)\n\n## 建議使用方式\n\n- 在該 atom scope 內建議只使用一次 hook 並將 refetch 函數用傳遞方式傳下去(或是使用 Context)。使用多次的風險為參數會有好幾份並且都是改同一個 atom，會造成混亂。\n- 在同一個 scope 底下想要用兩份相同 API 並且互不干擾的資料，請直接用 `createQueryAtom` 建兩個 atom 出來。\n\n## 方法\n\n- `createQueryAtom`\n- `createInvalidatedAtom`\n- `useMutation`\n\ncreate\n\n```typescript\nexport const [resultAtom, useApi] = createQueryAtom(fetchApi);\n```\n\n```jsx\nconst Component = () =\u003e {\n  const result = useAtomValue(resultAtom)\n\n  // auto fetch in mount\n  const refetch = useApi({params: xxx, enable: true})\n\n  const { mutate } = useMutation(xxxMutation, invalidatedAtom)\n\n  // ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffizzyelt%2Fcustom-jotai-query-poc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffizzyelt%2Fcustom-jotai-query-poc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffizzyelt%2Fcustom-jotai-query-poc/lists"}