{"id":16085831,"url":"https://github.com/zapolnoch/mobx-with-query","last_synced_at":"2025-03-18T06:30:36.107Z","repository":{"id":208496697,"uuid":"721800275","full_name":"zapolnoch/mobx-with-query","owner":"zapolnoch","description":"Like react-query but for MobX and simpler","archived":false,"fork":false,"pushed_at":"2023-11-21T20:07:49.000Z","size":4,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T21:52:52.078Z","etag":null,"topics":["mobx","mobx-react","query"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mobx-with-query","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zapolnoch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-11-21T19:48:17.000Z","updated_at":"2025-01-21T17:46:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c6e2f9f-5be2-4275-b1ad-f8bb1738a78a","html_url":"https://github.com/zapolnoch/mobx-with-query","commit_stats":null,"previous_names":["zapolnoch/mobx-with-query"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fmobx-with-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fmobx-with-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fmobx-with-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapolnoch%2Fmobx-with-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zapolnoch","download_url":"https://codeload.github.com/zapolnoch/mobx-with-query/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243906157,"owners_count":20366981,"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":["mobx","mobx-react","query"],"created_at":"2024-10-09T13:09:31.707Z","updated_at":"2025-03-18T06:30:36.097Z","avatar_url":"https://github.com/zapolnoch.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WithQuery\n\nIt makes fetching and updating server state in your MobX-store a breeze.\n\n## Usage\n\n```ts\nimport { WithQuery } from \"mobx-with-query\"\n\nclass Store {\n  constructor() {\n    makeAutoObservable(this)\n  }\n\n  data = new WithQuery(() =\u003e\n    fetch(\"https://api.github.com/repos/tannerlinsley/react-query\"),\n  )\n}\n```\n\nIn your React-component:\n\n```tsx\nconst Page = observer(() =\u003e {\n  const [store] = useState(() =\u003e new Store())\n  const { isLoading, data, error } = store.data\n\n  if (isLoading) return \"Loading...\"\n\n  if (error) return \"An error has occurred: \" + error.message\n\n  return \u003cdiv\u003e{data.name}\u003c/div\u003e\n})\n```\n\n## Config\n\nThe `onError` and `onSuccess` can be used to handle these events:\n\n```ts\nclass Store {\n  data = new WithQuery(Api.getMethod, {\n    onError: () =\u003e alert(\"Server Error. Please try again later\"),\n    onSuccess: () =\u003e alert(\"Completed successfully\"),\n  })\n}\n```\n\nYou can disable automatic data loading using `loadOnMount`. In addition, you can transform the response using mapping:\n\n```tsx\nclass Store {\n  project = new WithQuery(Api.getProject, {\n    loadOnMount: false,\n    transform: (data) =\u003e data?.name.toUpperCase(),\n  })\n}\n\nconst Page = observer(() =\u003e {\n  const [store] = useState(() =\u003e new Store())\n  const { id } = useParams()\n\n  useEffect(() =\u003e {\n    project.load(id)\n  }, [id])\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapolnoch%2Fmobx-with-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzapolnoch%2Fmobx-with-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapolnoch%2Fmobx-with-query/lists"}