{"id":20809568,"url":"https://github.com/ilham-pratama/use-url-sync","last_synced_at":"2026-04-04T16:36:08.904Z","repository":{"id":38421547,"uuid":"365710186","full_name":"Ilham-Pratama/use-url-sync","owner":"Ilham-Pratama","description":"⚛️ use-url-sync is a utility package that helps you sync your states to url without hassle","archived":false,"fork":false,"pushed_at":"2023-01-07T07:36:15.000Z","size":849,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T03:45:58.220Z","etag":null,"topics":["custom-hooks","hooks","npm","react","react-hooks","typescript","url-states","yarn"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Ilham-Pratama.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}},"created_at":"2021-05-09T09:03:27.000Z","updated_at":"2022-06-04T06:50:12.000Z","dependencies_parsed_at":"2023-02-06T15:00:55.284Z","dependency_job_id":null,"html_url":"https://github.com/Ilham-Pratama/use-url-sync","commit_stats":null,"previous_names":["ilham-pratama/use-url-state"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilham-Pratama%2Fuse-url-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilham-Pratama%2Fuse-url-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilham-Pratama%2Fuse-url-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilham-Pratama%2Fuse-url-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ilham-Pratama","download_url":"https://codeload.github.com/Ilham-Pratama/use-url-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243155033,"owners_count":20245023,"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":["custom-hooks","hooks","npm","react","react-hooks","typescript","url-states","yarn"],"created_at":"2024-11-17T20:14:28.047Z","updated_at":"2025-12-25T16:26:28.450Z","avatar_url":"https://github.com/Ilham-Pratama.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-url-sync\n\n![npm](https://img.shields.io/npm/v/use-url-sync) ![CI](https://github.com/Ilham-Pratama/use-url-sync/actions/workflows/main-ci.yml/badge.svg) ![minizip](https://badgen.net/bundlephobia/minzip/use-url-sync)\n\n**use-url-sync** is a set of tools that help you sync your state to URL.\nAlong with this package, you can do some awesome stuff, such as:\n\n- Use state hook `useUrlState` to get value from current page path\n- Sync your states's values to path using `useUrlSync` or `getUrlString`\n\n## 🖥️ Example\n\nLet's say that the path is `/user?name=andy\u0026page=1\u0026isEmployee=false`\n\n```jsx\nimport React from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { useSyncUrl, useUrlState } from 'use-url-sync';\n\nconst App = () =\u003e {\n  const location = useLocation();\n\n  /* Retrieve value from URL */\n  const [page, setPage] = useUrlState({\n    name: 'page',\n    defaultValue: 0,\n    onExists: p =\u003e parseInt(p, 10)\n  });\n  const [name, setName] = useUrlState({\n    name: 'name',\n    defaultValue: ''\n  });\n  const [isEmployee, setIsEmployee] = useUrlState({\n    name: 'isEmployee',\n    defaultValue: false,\n    onExists: v =\u003e v === 'true'\n  });\n\n  /* Sync states to path */\n  useUrlSync(\n    {\n      states: {\n        name,\n        page,\n        isEmployee: `${isEmployee}`\n      },\n      /* Ignored conditions */\n      ignore: {\n        page: p =\u003e p === 0\n      }\n    },\n    nextPath =\u003e {\n      location.replace(nextPath);\n    }\n  );\n\n  const incrementPage = () =\u003e setPage(p =\u003e p + 1);\n\n  const decrementPage = () =\u003e setPage(p =\u003e p - 1);\n\n  const toggleEmployeeStatus = () =\u003e {\n    setIsEmployee(v =\u003e !v);\n  };\n\n  return (\n    \u003c\u003e\n      \u003cdiv id=\"page-togglers\"\u003e\n        \u003cbutton type=\"button\" id=\"increase-page\" onClick={incrementPage}\u003e\n          + 1\n        \u003c/button\u003e\n        \u003cbutton type=\"button\" id=\"decrease-page\" onClick={decrementPage}\u003e\n          - 1\n        \u003c/button\u003e\n      \u003c/div\u003e\n      \u003cbutton type=\"button\" id=\"toggle-status\" onClick={toggleEmployeeStatus}\u003e\n        Toggle Employee Status\n      \u003c/button\u003e\n      \u003cp id=\"current-page\"\u003e{page}\u003c/p\u003e\n      \u003cp id=\"current-name\"\u003e{name}\u003c/p\u003e\n      \u003cp id=\"current-isEmployee\"\u003e{isEmployee ? 'true' : 'false'}\u003c/p\u003e\n    \u003c/\u003e\n  );\n};\n```\n\n## 💾 Installation\n\n```sh\nnpm install use-url-sync\n```\n\nor\n\n```sh\nyarn add use-url-sync\n```\n\n## ✔️ TypeScript Support\n\nThis package contains an `index.d.ts` type definition file, so you can use it in TypeScript without extra configuration.\n\n```tsx\n  ...\n\n  const [page, setPage] = useUrlState\u003cnumber\u003e({\n    name: 'page',\n    defaultValue: 0,\n    onExists: (p: any) =\u003e parseInt(p, 10)\n  });\n  const [name, setName] = useUrlState\u003cstring\u003e({\n    name: 'name',\n    defaultValue: ''\n  });\n\n  interface IStates {\n    page: number;\n    name: string;\n  }\n\n  useUrlSync\u003cIStates\u003e(\n    {\n      states: {\n        page,\n        name\n      },\n      ignore: {\n        page: (p: number) =\u003e p === 0\n      }\n    },\n    (nextPath: string) =\u003e {\n      location.replace(nextPath);\n    }\n  );\n\n  ...\n```\n\n## 🏷️ LICENSE\n\nMIT License\n\nCopyright (c) 2021 Ilham-Pratama\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filham-pratama%2Fuse-url-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filham-pratama%2Fuse-url-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filham-pratama%2Fuse-url-sync/lists"}