{"_id":"use-url-storage-state","_rev":"4-28ceff6d1e50e07489ef6d7e0d0f7128","name":"use-url-storage-state","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"use-url-storage-state","version":"1.0.0","keywords":["react","hook","url","state","query parameters","react-router"],"author":"","license":"MIT","_id":"use-url-storage-state@1.0.0","maintainers":[{"name":"or.duer","email":"orrduer@gmail.com"}],"homepage":"https://github.com/orduer/use-url-storage-state#readme","bugs":{"url":"https://github.com/orduer/use-url-storage-state/issues"},"dist":{"shasum":"ee926903f03cdcce4ef371188bc6fcb440c1feae","tarball":"https://registry.npmjs.org/use-url-storage-state/-/use-url-storage-state-1.0.0.tgz","fileCount":3,"integrity":"sha512-HU+tN4ruJxHZnjsOo8cXH1gKEOoUpcsLA+86tj6raugccW3SN6zeE/lRLOAIuRd2ZIfoRigRI0oc5i2jk6ECiA==","signatures":[{"sig":"MEYCIQD/s806fVjQdRCabhQA7rAMRvKWJ1nPaFWXg5lCUQue3wIhAKvJs0ses2RX9GMiMd1jXOECuWOB1y77S1tBtY+HsbX9","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8593},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","gitHead":"d44b0353b354e6a36ea6a475c6b594a89d6f847e","scripts":{"dev":"vite","lint":"eslint src","test":"vitest","build":"rolldown -c","format":"prettier --write \"src/**/*.{js,jsx,ts,tsx}\"","prepare":"husky","preview":"vite preview","typecheck":"tsc --noEmit","test:watch":"vitest watch","test:coverage":"vitest run --coverage","prepublishOnly":"pnpm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"or.duer","email":"orrduer@gmail.com"},"repository":{"url":"git+https://github.com/orduer/use-url-storage-state.git","type":"git"},"_npmVersion":"10.9.0","description":"React hook for syncing state with URL parameters","directories":{},"lint-staged":{"**/*":"prettier --write --ignore-unknown","**/*.{js,ts}":["eslint --fix"]},"sideEffects":false,"_nodeVersion":"22.12.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.0.7","husky":"^9.1.7","jsdom":"^26.0.0","react":"^19.0.0","eslint":"^9.18.0","vitest":"^2.1.8","prettier":"^3.4.2","rolldown":"1.0.0-beta.1","react-dom":"^19.0.0","@eslint/js":"^9.18.0","typescript":"~5.7.3","lint-staged":"^15.3.0","@types/react":"^19.0.6","@types/eslint":"^9.6.1","@commitlint/cli":"^19.6.1","vite-plugin-dts":"^4.5.0","@types/react-dom":"^19.0.3","react-router-dom":"^6.28.1","rollup-plugin-ts":"^3.4.5","semantic-release":"^24.2.1","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.20.0","eslint-plugin-react":"^7.37.4","@rollup/plugin-alias":"^5.1.1","@testing-library/dom":"^10.4.0","@vitejs/plugin-react":"^4.2.0","eslint-plugin-import":"^2.31.0","@semantic-release/npm":"^12.0.1","@semantic-release/exec":"^6.0.3","@testing-library/react":"^16.1.0","eslint-config-prettier":"^10.0.1","eslint-plugin-jsx-a11y":"^6.10.2","eslint-plugin-prettier":"^5.2.1","@semantic-release/github":"^11.0.1","@rollup/plugin-typescript":"^12.1.2","@testing-library/jest-dom":"^6.6.3","@typescript-eslint/parser":"^8.20.0","eslint-plugin-react-hooks":"^5.1.0","@testing-library/user-event":"^14.5.2","@commitlint/config-conventional":"^19.6.0","@typescript-eslint/eslint-plugin":"^8.20.0","rollup-plugin-peer-deps-external":"^2.2.4","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/release-notes-generator":"^14.0.3"},"peerDependencies":{"react":"^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0","react-router-dom":"^6.28.1"},"_npmOperationalInternal":{"tmp":"tmp/use-url-storage-state_1.0.0_1736852778558_0.48843919878442654","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"use-url-storage-state","version":"1.1.0","keywords":["react","hook","url","state","query parameters","react-router"],"author":"","license":"MIT","_id":"use-url-storage-state@1.1.0","maintainers":[{"name":"or.duer","email":"orrduer@gmail.com"}],"homepage":"https://github.com/orduer/use-url-storage-state#readme","bugs":{"url":"https://github.com/orduer/use-url-storage-state/issues"},"dist":{"shasum":"8432aef050277774459d70de6471e64b6462e1b8","tarball":"https://registry.npmjs.org/use-url-storage-state/-/use-url-storage-state-1.1.0.tgz","fileCount":5,"integrity":"sha512-f1fNuQGBhfsJhawaJPvJvUy/tQkUZU+MT0GgGVPdXrEug0phiTE5XvtkySKWyublpcFcg5OHEoVhtpF1YBcYHQ==","signatures":[{"sig":"MEUCIC8mC+3h4L+RWb68EcSnFx/wpRiUJ60c2X03+lMEsAnIAiEAmfzuffnw/Rle+84Z1mi3PL5vXlckoiDMnFH9/GafisM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19538},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","gitHead":"eea1348d74dfd1becdc5e9b5c418844ff670cab7","scripts":{"dev":"vite","lint":"eslint src","test":"vitest","build":"rolldown -c","format":"prettier --write \"src/**/*.{js,jsx,ts,tsx}\"","prepare":"husky","preview":"vite preview","typecheck":"tsc --noEmit","test:watch":"vitest watch","test:coverage":"vitest run --coverage","prepublishOnly":"pnpm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"or.duer","email":"orrduer@gmail.com"},"repository":{"url":"git+https://github.com/orduer/use-url-storage-state.git","type":"git"},"_npmVersion":"10.9.2","description":"React hook for syncing state with URL parameters","directories":{},"lint-staged":{"**/*":"prettier --write --ignore-unknown","**/*.{js,ts}":["eslint --fix"]},"sideEffects":false,"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.0.7","husky":"^9.1.7","jsdom":"^26.0.0","react":"^19.0.0","eslint":"^9.18.0","vitest":"^2.1.8","prettier":"^3.4.2","rolldown":"1.0.0-beta.1","react-dom":"^19.0.0","@eslint/js":"^9.18.0","typescript":"~5.7.3","lint-staged":"^15.3.0","@types/react":"^19.0.6","@types/eslint":"^9.6.1","@commitlint/cli":"^19.6.1","vite-plugin-dts":"^4.5.0","@types/react-dom":"^19.0.3","react-router-dom":"^6.28.1","rollup-plugin-ts":"^3.4.5","semantic-release":"^24.2.1","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.20.0","eslint-plugin-react":"^7.37.4","@rollup/plugin-alias":"^5.1.1","@testing-library/dom":"^10.4.0","@vitejs/plugin-react":"^4.2.0","eslint-plugin-import":"^2.31.0","@semantic-release/npm":"^12.0.1","@semantic-release/exec":"^6.0.3","@testing-library/react":"^16.1.0","eslint-config-prettier":"^10.0.1","eslint-plugin-jsx-a11y":"^6.10.2","eslint-plugin-prettier":"^5.2.1","@semantic-release/github":"^11.0.1","@rollup/plugin-typescript":"^12.1.2","@testing-library/jest-dom":"^6.6.3","@typescript-eslint/parser":"^8.20.0","eslint-plugin-react-hooks":"^5.2.0","@testing-library/user-event":"^14.5.2","@commitlint/config-conventional":"^19.6.0","@typescript-eslint/eslint-plugin":"^8.20.0","rollup-plugin-peer-deps-external":"^2.2.4","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/release-notes-generator":"^14.0.3"},"peerDependencies":{"react":"^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0","react-router-dom":"^6.28.1"},"_npmOperationalInternal":{"tmp":"tmp/use-url-storage-state_1.1.0_1742998392669_0.6660758202385868","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"use-url-storage-state","version":"1.1.1","keywords":["react","hook","url","state","query parameters","react-router"],"author":"","license":"MIT","_id":"use-url-storage-state@1.1.1","maintainers":[{"name":"or.duer","email":"orrduer@gmail.com"}],"homepage":"https://github.com/orduer/use-url-storage-state#readme","bugs":{"url":"https://github.com/orduer/use-url-storage-state/issues"},"dist":{"shasum":"00fac52ddb5c6b7eca67b6bf12246e797a9244c2","tarball":"https://registry.npmjs.org/use-url-storage-state/-/use-url-storage-state-1.1.1.tgz","fileCount":5,"integrity":"sha512-QYxcKfOA3lVDPhPXdr2dYCCTgY7UAkglvkOm1YT8mjlAPJRFK8gpTWcItOP75HomQIUYEk8cZw/3/zGVvp4Epw==","signatures":[{"sig":"MEYCIQDtONiH86drnjEfby/NBJF+X0pZn7Os0jyLG8QBthe69AIhAOEKSUIwFbqn4bzUuiuj0wucgTMoYjsM4ZAqoLAs6iEj","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19359},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","gitHead":"90337a4f5b31ad468f4f2c095e52b36b702b3d1f","scripts":{"dev":"vite","lint":"eslint src","test":"vitest","build":"rolldown -c","format":"prettier --write \"src/**/*.{js,jsx,ts,tsx}\"","prepare":"husky","preview":"vite preview","typecheck":"tsc --noEmit","test:watch":"vitest watch","test:coverage":"vitest run --coverage","prepublishOnly":"pnpm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"or.duer","email":"orrduer@gmail.com"},"repository":{"url":"git+https://github.com/orduer/use-url-storage-state.git","type":"git"},"_npmVersion":"10.9.2","description":"React hook for syncing state with URL parameters","directories":{},"lint-staged":{"**/*":"prettier --write --ignore-unknown","**/*.{js,ts}":["eslint --fix"]},"sideEffects":false,"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.0.7","husky":"^9.1.7","jsdom":"^26.0.0","react":"^19.0.0","eslint":"^9.18.0","vitest":"^2.1.8","prettier":"^3.4.2","rolldown":"1.0.0-beta.1","react-dom":"^19.0.0","@eslint/js":"^9.18.0","typescript":"~5.7.3","lint-staged":"^15.3.0","@types/react":"^19.0.6","@types/eslint":"^9.6.1","@commitlint/cli":"^19.6.1","vite-plugin-dts":"^4.5.0","@types/react-dom":"^19.0.3","react-router-dom":"^6.28.1","rollup-plugin-ts":"^3.4.5","semantic-release":"^24.2.1","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.20.0","eslint-plugin-react":"^7.37.4","@rollup/plugin-alias":"^5.1.1","@testing-library/dom":"^10.4.0","@vitejs/plugin-react":"^4.2.0","eslint-plugin-import":"^2.31.0","@semantic-release/npm":"^12.0.1","@semantic-release/exec":"^6.0.3","@testing-library/react":"^16.1.0","eslint-config-prettier":"^10.0.1","eslint-plugin-jsx-a11y":"^6.10.2","eslint-plugin-prettier":"^5.2.1","@semantic-release/github":"^11.0.1","@rollup/plugin-typescript":"^12.1.2","@testing-library/jest-dom":"^6.6.3","@typescript-eslint/parser":"^8.20.0","eslint-plugin-react-hooks":"^5.2.0","@testing-library/user-event":"^14.5.2","@commitlint/config-conventional":"^19.6.0","@typescript-eslint/eslint-plugin":"^8.20.0","rollup-plugin-peer-deps-external":"^2.2.4","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/release-notes-generator":"^14.0.3"},"peerDependencies":{"react":"^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0","react-router-dom":"^6.28.1"},"_npmOperationalInternal":{"tmp":"tmp/use-url-storage-state_1.1.1_1743001405727_0.6650230079700585","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"use-url-storage-state","version":"1.2.0","description":"React hook for syncing state with URL parameters","type":"module","lint-staged":{"**/*.{js,ts}":["eslint --fix"],"**/*":"prettier --write --ignore-unknown"},"keywords":["react","hook","url","state","query parameters","react-router"],"author":"","license":"MIT","repository":{"type":"git","url":"git+https://github.com/orduer/use-url-storage-state.git"},"bugs":{"url":"https://github.com/orduer/use-url-storage-state/issues"},"homepage":"https://github.com/orduer/use-url-storage-state#readme","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"dev":"vite","build":"rolldown -c","preview":"vite preview","test":"vitest","test:watch":"vitest watch","test:coverage":"vitest run --coverage","typecheck":"tsc --noEmit","lint":"eslint src","prepublishOnly":"pnpm run build","format":"prettier --write \"src/**/*.{js,jsx,ts,tsx}\"","prepare":"husky","semantic-release":"semantic-release"},"peerDependencies":{"react":"^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0","react-router-dom":"^6.28.1"},"devDependencies":{"@commitlint/cli":"^19.6.1","@commitlint/config-conventional":"^19.6.0","@eslint/js":"^9.18.0","@rollup/plugin-alias":"^5.1.1","@rollup/plugin-typescript":"^12.1.2","@semantic-release/commit-analyzer":"^13.0.1","@semantic-release/exec":"^6.0.3","@semantic-release/github":"^11.0.1","@semantic-release/npm":"^12.0.1","@semantic-release/release-notes-generator":"^14.0.3","@testing-library/dom":"^10.4.0","@testing-library/jest-dom":"^6.6.3","@testing-library/react":"^16.1.0","@testing-library/user-event":"^14.5.2","@types/eslint":"^9.6.1","@types/react":"^19.0.6","@types/react-dom":"^19.0.3","@typescript-eslint/eslint-plugin":"^8.20.0","@typescript-eslint/parser":"^8.20.0","@vitejs/plugin-react":"^4.2.0","eslint":"^9.18.0","eslint-config-prettier":"^10.0.1","eslint-plugin-import":"^2.31.0","eslint-plugin-jsx-a11y":"^6.10.2","eslint-plugin-prettier":"^5.2.1","eslint-plugin-react":"^7.37.4","eslint-plugin-react-hooks":"^5.2.0","husky":"^9.1.7","jsdom":"^26.0.0","lint-staged":"^15.3.0","prettier":"^3.4.2","react":"^19.0.0","react-dom":"^19.0.0","react-router-dom":"^6.28.1","rolldown":"1.0.0-beta.1","rollup-plugin-dts":"^6.1.1","rollup-plugin-peer-deps-external":"^2.2.4","rollup-plugin-ts":"^3.4.5","semantic-release":"^24.2.1","typescript":"~5.7.3","typescript-eslint":"^8.20.0","vite":"^6.0.7","vite-plugin-dts":"^4.5.0","vitest":"^2.1.8"},"sideEffects":false,"publishConfig":{"access":"public"},"gitHead":"c9fb1bfee3841b5aaf98da39112ca596ad069182","_id":"use-url-storage-state@1.2.0","_nodeVersion":"24.16.0","_npmVersion":"11.17.0","dist":{"integrity":"sha512-k6IoM5qBaYwwYYn4asx9gwF6dT2IjsMiQMat+a/5X0TJLBxdtbLfLOcsVnQlZqtPSHHnWhAQhx3IXxOX732q1A==","shasum":"9cf11592cea45d3ced3fcdf0cac4fc74c2ff4344","tarball":"https://registry.npmjs.org/use-url-storage-state/-/use-url-storage-state-1.2.0.tgz","fileCount":5,"unpackedSize":20674,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/use-url-storage-state@1.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCM8SAbfCQrS5uZwO3yZ3EyXRVdFHq4OI5VkhHXtsu2EwIgQ5D4FNXxmHa+aONJC5FCJsaVmOPCfiFZtV8LB869DEA="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:91b89458-4796-4f6a-8969-7310672f3af9"}},"directories":{},"maintainers":[{"name":"or.duer","email":"orrduer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/use-url-storage-state_1.2.0_1781439671216_0.809695980283685"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-14T11:06:18.443Z","modified":"2026-06-14T12:21:11.744Z","1.0.0":"2025-01-14T11:06:18.717Z","1.1.0":"2025-03-26T14:13:12.881Z","1.1.1":"2025-03-26T15:03:25.921Z","1.2.0":"2026-06-14T12:21:11.350Z"},"bugs":{"url":"https://github.com/orduer/use-url-storage-state/issues"},"license":"MIT","homepage":"https://github.com/orduer/use-url-storage-state#readme","keywords":["react","hook","url","state","query parameters","react-router"],"repository":{"type":"git","url":"git+https://github.com/orduer/use-url-storage-state.git"},"description":"React hook for syncing state with URL parameters","maintainers":[{"name":"or.duer","email":"orrduer@gmail.com"}],"readme":"# useUrlStorageState Hook\n\n## Table of Contents\n\n- [🌟 Overview](#-overview)\n- [🚀 Features](#-features)\n- [📚 Installation](#-installation)\n- [✨ Demo](#-demo)\n- [🛠️ API](#️-api)\n  - [Parameters](#parameters)\n  - [Returns](#returns)\n- [🔧 Usage Examples](#-usage-examples)\n  - [Basic Usage](#basic-usage)\n  - [With Custom Prefix](#with-custom-prefix)\n  - [Default Prefix as Pathname](#default-prefix-as-pathname)\n  - [Using Session Storage](#using-session-storage)\n  - [Managing Multiple States](#managing-multiple-states)\n- [📝 Notes](#-notes)\n- [📦 useStorage Hook](#-usestorage-hook)\n  - [🌟 Overview](#-overview-1)\n  - [🚀 Features](#-features-1)\n  - [🛠️ API](#️-api-1)\n    - [Parameters](#parameters-1)\n    - [Returns](#returns-1)\n  - [🔧 Usage Examples](#-usage-examples-1)\n    - [Basic Usage](#basic-usage-1)\n    - [Custom Serialization](#custom-serialization)\n    - [Live Synchronization](#live-synchronization)\n    - [Using `forceInit` for Conditional Initialization](#using-forceinit-for-conditional-initialization)\n    - [Specifying `sessionStorage` Instead of `localStorage`](#specifying-sessionstorage-instead-of-localstorage)\n  - [📝 Notes](#-notes-1)\n- [📜 License](#-license)\n- [🎉 Acknowledgments](#-acknowledgments)\n\n## 🌟 Overview\n\n`useUrlStorageState` is a hook designed to synchronize state between URL parameters and browser storage (e.g., `localStorage` or `sessionStorage`). This hook helps you maintain consistent state across page refreshes, multiple tabs, and deep links while allowing for custom configurations.\n\n## 🚀 Features\n\n- **Bidirectional Sync**: Synchronizes state between URL parameters and browser storage seamlessly.\n- **Persistence**: Retains state across page refreshes.\n- **Type Safety**: Fully generic for strongly-typed state.\n- **Customizable**: Supports custom storage, key prefixing, and serialization methods.\n- **Multi-State Management**: Easily handles multiple independent states.\n\n## 📚 Installation\n\nInstall the package via npm or yarn:\n\n```bash\nnpm install use-url-storage-state\n```\n\nEnsure that `react` and `react-router-dom` are installed in your project\n\n## ✨ Demo\n\n```jsx\nimport React from 'react';\nimport { useUrlStorageState } from 'use-url-storage-state';\n\nconst Demo = () => {\n  const [filters, setFilters] = useUrlStorageState({\n    key: 'filters',\n    defaultValue: { search: '', category: 'all' },\n  });\n\n  return (\n    <div>\n      <input\n        type='text'\n        value={filters.search}\n        onChange={(e) => setFilters({ ...filters, search: e.target.value })}\n      />\n      <select\n        value={filters.category}\n        onChange={(e) => setFilters({ ...filters, category: e.target.value })}\n      >\n        <option value='all'>All</option>\n        <option value='electronics'>Electronics</option>\n        <option value='fashion'>Fashion</option>\n      </select>\n    </div>\n  );\n};\n\nexport default Demo;\n```\n\n## 🛠️ API\n\n### Parameters\n\n```typescript\ntype useUrlStorageStateParams<T> = {\n  key: string; // URL parameter and storage key\n  defaultValue: T; // Default value if none exists\n  prefix?: string; // Optional storage key prefix (default: current pathname)\n  storage?: Storage; // Optional storage type (default: localStorage)\n  previousKeys?: string[]; // Old keys to remove from storage on mount\n};\n```\n\n### Returns\n\n```typescript\n[T, (newValue: T | ((prev: T) => T)) => void]\n```\n\n- `T`: The current state value.\n- `(newValue: T | ((prev: T) => T)) => void`: A function to update the state.\n\n## 🔧 Usage Examples\n\n### Basic Usage\n\n```tsx\nimport { useUrlStorageState } from 'use-url-storage-state';\n\nconst [filters, setFilters] = useUrlStorageState({\n  key: 'filters',\n  defaultValue: { search: '', category: 'all' },\n});\n\n// URL: http://localhost:3000/?filters={\"search\":\"\",\"category\":\"all\"}\n// Storage: urlStorage_/current_pathname_filters\n```\n\n### With Custom Prefix\n\nUsing a shared prefix is useful when you want states across different paths or to share the same logical grouping in storage. For example, you might want all multiple pages to affect and persist the same url params:\n\n```tsx\nimport { useUrlStorageState } from 'use-url-storage-state';\n\nconst [filters, setFilters] = useUrlStorageState({\n  key: 'filters',\n  defaultValue: { search: '', category: 'all' },\n  prefix: 'somePrefix',\n});\n\n// URL: http://localhost:3000/?filters={\"search\":\"\",\"category\":\"all\"}\n// Storage: somePrefix_filters\n```\n\n### Default Prefix as Pathname\n\nBy default, the prefix is set to the current `location.pathname`. This ensures that states are unique to each page in your application. For instance, if you navigate from `/home` to `/profile`, the storage keys will differ:\n\n- `/home`: `urlStorage_/home_filters`\n- `/profile`: `urlStorage_/profile_filters`\n\nThis behavior prevents cross-page conflicts and keeps the state isolated to its corresponding route.\n\n### Using Session Storage\n\n```tsx\nimport { useUrlStorageState } from 'use-url-storage-state';\n\nconst [sessionState, setSessionState] = useUrlStorageState({\n  key: 'userSession',\n  defaultValue: { loggedIn: false },\n  storage: sessionStorage,\n});\n```\n\n### Managing Multiple States\n\n```tsx\nimport { useUrlStorageState } from 'use-url-storage-state';\n\nconst [filters, setFilters] = useUrlStorageState({\n  key: 'filters',\n  defaultValue: { search: '', category: 'all' },\n});\n\nconst [theme, setTheme] = useUrlStorageState({\n  key: 'theme',\n  defaultValue: { darkMode: false },\n});\n```\n\n### Cleaning Up Old Storage Keys\n\nWhen you rename a key, pass the old names via `previousKeys` to remove stale storage entries on mount:\n\n```tsx\nimport { useUrlStorageState } from 'use-url-storage-state';\n\nconst [filters, setFilters] = useUrlStorageState({\n  key: 'search_filters',\n  defaultValue: { search: '', category: 'all' },\n  previousKeys: ['filters', 'old_filters'], // removed from storage on mount\n});\n```\n\n## 📝 Notes\n\n1. URL parameters are always strings, so complex objects are automatically serialized/deserialized\n2. The hook maintains sync between URL and storage.\n   - If a URL parameter exists, it will update the storage\n   - If a storage value exists, and no URL parameter exists, it will update the URL\n   - If none exists, it will populate the URL and storage with the default value\n3. The default state will populate the URL and storage if none exists automatically\n4. The hook will only refer to queryParams that exists in state, and will ignore any other query params\n\n## 📦 useStorage Hook\n\n### 🌟 Overview\n\nThe `useStorage` hook is a low-level utility for interacting with browser storage (e.g., `localStorage`, `sessionStorage`). It provides reactive state management tied to storage keys, making it easy to persist and retrieve data.\n\n### 🚀 Features\n\n- **Custom Serialization**: Allows for custom serialization and deserialization of storage values.\n- **Live Synchronization**: Keeps state synchronized across tabs.\n- **Default Value Initialization**: Initializes storage keys with default values.\n\n### 🛠️ API\n\n#### Parameters\n\n```typescript\ntype StorageProps<ValueType> = {\n  key: string; // The storage key.\n  defaultValue: ValueType; // Default value if no value exists.\n  storage?: Storage; // Storage type (localStorage/sessionStorage). Default: localStorage.\n  live?: boolean; // Synchronize across tabs. Default: false.\n  serialize?: (value: ValueType) => string; // Custom serialization function. Default: JSON.stringify.\n  deserialize?: (str: string) => ValueType; // Custom deserialization function. Default: JSON.parse.\n  forceInit?: (value?: string) => boolean; // Force initialization logic. Default: never.\n  previousKeys?: string[]; // Old keys to remove from storage on mount.\n};\n```\n\n#### Returns\n\n```typescript\n[ValueType, (newValue: ValueType | ((prev: ValueType) => ValueType)) => void]\n```\n\n### 🔧 Usage Examples\n\n#### Basic Usage\n\n```tsx\nimport { useStorage } from 'use-url-storage-state';\n\nconst [value, setValue] = useStorage({\n  key: 'myKey',\n  defaultValue: 'defaultValue',\n});\n\nsetValue('newValue');\n```\n\n#### Custom Serialization\n\n```tsx\nimport { useStorage } from 'use-url-storage-state';\n\nconst [user, setUser] = useStorage({\n  key: 'user',\n  defaultValue: { name: 'Guest' },\n  serialize: (value) => btoa(JSON.stringify(value)),\n  deserialize: (str) => JSON.parse(atob(str)),\n});\n```\n\n#### Live Synchronization\n\n```tsx\nimport { useStorage } from 'use-url-storage-state';\n\nconst [theme, setTheme] = useStorage({\n  key: 'theme',\n  defaultValue: 'light',\n  live: true,\n});\n```\n\n#### Using `forceInit` for Conditional Initialization\n\n```tsx\nimport { useStorage } from 'use-url-storage-state';\n\nconst [count, setCount] = useStorage({\n  key: 'counter',\n  defaultValue: 0,\n  forceInit: (existingValue) =>\n    existingValue === undefined || existingValue === null,\n});\n\n// The key will be initialized to 0 only if it doesn't exist or is null.\nsetCount((prev) => prev + 1);\n```\n\n#### Specifying `sessionStorage` Instead of `localStorage`\n\n```tsx\nimport { useStorage } from 'use-url-storage-state';\n\nconst [sessionData, setSessionData] = useStorage({\n  key: 'sessionKey',\n  defaultValue: 'sessionValue',\n  storage: sessionStorage,\n});\n\nsetSessionData('newSessionValue');\n```\n\n### 📝 Notes\n\n1. **Storage Type**: The default storage is `localStorage`. If you need ephemeral data that clears on browser close, use `sessionStorage` by setting the `storage` option.\n2. **Custom Serialization**: Use `serialize` and `deserialize` when working with complex objects, or when you need encrypted or encoded storage.\n3. **Live Synchronization**: Enable the `live` option for use cases that require real-time updates across browser tabs or windows, like theme synchronization or shared state.\n4. **Force Initialization**: The `forceInit` function is useful for cases where existing values might be invalid or require resetting.\n\n## 📜 License\n\nThis project is licensed under the MIT License\n\n## 🎉 Acknowledgments\n\n- Inspired by Kent C. Dodds, https://www.youtube.com/watch?v=yu3dnHrnps4\n- Special thanks to [Idan Entin](https://github.com/idanen)\n","readmeFilename":"README.md"}