{"_id":"@bndl-io/use-local-storage","_rev":"3-015f35686d841dac737021934af0e610","name":"@bndl-io/use-local-storage","dist-tags":{"latest":"1.1.0"},"versions":{"0.0.1":{"name":"@bndl-io/use-local-storage","version":"0.0.1","author":{"name":"Ramon Gebben","email":"ramon@dathuis.nl"},"license":"ISC","_id":"@bndl-io/use-local-storage@0.0.1","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"dist":{"shasum":"54b5cb440a4f273e697f4fc2a67d6493e320441a","tarball":"https://registry.npmjs.org/@bndl-io/use-local-storage/-/use-local-storage-0.0.1.tgz","fileCount":6,"integrity":"sha512-bIhUB14rh679hKxJkfA1bp8TYYWwCe6bV3wvJEWZoRt7dZKSRNhehxKKFMMRGD/qDOAa9kKMMaor+5gU0LlHeA==","signatures":[{"sig":"MEQCIDbr5KkQaGKecSld/o4YNoHXn7nqrJl01TkvUfpoTu1zAiAkT5T2BAW7Hl9KiLnPyKYiFsHTMDyHCnXNrxUK7ir6rA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5084},"main":"dist/useLocalStorageValue.js","types":"dist/useLocalStorageValue.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"_npmVersion":"10.8.2","description":"A hook to set and use values from localstorage, safely","directories":{},"_nodeVersion":"20.18.0","dependencies":{"react":"^18.3.1"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.16.0","csstype":"^3.1.3","prettier":"^3.4.2","typescript":"^5.7.2","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@types/prop-types":"^15.7.13"},"_npmOperationalInternal":{"tmp":"tmp/use-local-storage_0.0.1_1733321908563_0.9734850926896137","host":"s3://npm-registry-packages"}},"1.0.0":{"name":"@bndl-io/use-local-storage","version":"1.0.0","keywords":["react","hook","localstorage","typescript"],"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","_id":"@bndl-io/use-local-storage@1.0.0","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"homepage":"https://github.com/DatHuis/-bndl-io-use-local-storage#readme","bugs":{"url":"https://github.com/DatHuis/-bndl-io-use-local-storage/issues"},"dist":{"shasum":"478195c1e8c71d1d3dc8e4ff6be7be62c72042c8","tarball":"https://registry.npmjs.org/@bndl-io/use-local-storage/-/use-local-storage-1.0.0.tgz","fileCount":9,"integrity":"sha512-silT4uaq63tZZz+kFEp1QjwFf2jolMrKyx9tup6XaWwKGwLv0lNGyLlyo4dMH0xy01lyKkUbdj4th9aszEDdVA==","signatures":[{"sig":"MEYCIQCLLOIMY1YipFto5kqTBypJbqVPFgjqnD681kankXi2QAIhAP9H4DEihLCHyTa1AJCMSk34z6Fkob4on6mG/szdXw2j","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7993},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"jest","build":"rm -rf dist/ && tsc"},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"repository":{"url":"git+https://github.com/DatHuis/-bndl-io-use-local-storage.git","type":"git"},"_npmVersion":"10.8.2","description":"A React hook to manage local storage values as state.","directories":{},"_nodeVersion":"20.18.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","csstype":"^3.x","ts-jest":"^29.2.5","typescript":"^4.x","@types/jest":"^29.5.14","@types/react":"^18.x","@types/react-dom":"^18.x","@types/prop-types":"^15.x","@testing-library/react":"^16.0.1","jest-environment-jsdom":"^29.7.0","@testing-library/jest-dom":"^6.6.3"},"peerDependencies":{"react":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/use-local-storage_1.0.0_1733323308174_0.20859393891992872","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@bndl-io/use-local-storage","version":"1.0.1","keywords":["react","hook","localstorage","typescript"],"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","_id":"@bndl-io/use-local-storage@1.0.1","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"homepage":"https://github.com/DatHuis/-bndl-io-use-local-storage#readme","bugs":{"url":"https://github.com/DatHuis/-bndl-io-use-local-storage/issues"},"dist":{"shasum":"ed0c416eecdaedc3106cd7aa2642c11ebe6a910e","tarball":"https://registry.npmjs.org/@bndl-io/use-local-storage/-/use-local-storage-1.0.1.tgz","fileCount":11,"integrity":"sha512-YWdjNe9iZfrTNZgWqz+VOupn/5qfnW8/fdzujTiLxMDMZGhW1wJwbZLM4N4q0yApYp5eHm15mj4I5IDK5NL/Cw==","signatures":[{"sig":"MEYCIQCBSEvzBvMcC/r0sZmpSs8fM+gxYeLP5TEEm+YUyFJMPAIhAMTHkTBP/t6yb+8hlTVrnKTccj1SdX/tXXRYgYlQQ56j","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9764},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"964dc7be53701c7254ba820e64a4d5e2a2bc6dd6","scripts":{"test":"jest","build":"rm -rf dist/ && tsc"},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"repository":{"url":"git+https://github.com/DatHuis/-bndl-io-use-local-storage.git","type":"git"},"_npmVersion":"10.8.2","description":"A React hook to manage local storage values as state.","directories":{},"_nodeVersion":"20.18.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","csstype":"^3.x","ts-jest":"^29.2.5","typescript":"^4.x","@types/jest":"^29.5.14","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@types/prop-types":"^15.x","@testing-library/react":"^16.0.1","jest-environment-jsdom":"^29.7.0","@testing-library/jest-dom":"^6.6.3"},"peerDependencies":{"react":">=18.3.1"},"_npmOperationalInternal":{"tmp":"tmp/use-local-storage_1.0.1_1733324747179_0.2036766898267186","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@bndl-io/use-local-storage","version":"1.1.0","description":"A React hook to manage local storage values as state.","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"rm -rf dist/ && tsc","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/DatHuis/-bndl-io-use-local-storage.git"},"keywords":["react","hook","localstorage","typescript"],"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","peerDependencies":{"react":">=18.3.1"},"devDependencies":{"@testing-library/jest-dom":"^6.6.3","@testing-library/react":"^16.0.1","@types/jest":"^29.5.14","@types/prop-types":"^15.x","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","csstype":"^3.x","jest":"^29.7.0","jest-environment-jsdom":"^29.7.0","ts-jest":"^29.2.5","typescript":"^4.x"},"_id":"@bndl-io/use-local-storage@1.1.0","gitHead":"eaa83e531a3c194d645144072a9be0986eb572c3","bugs":{"url":"https://github.com/DatHuis/-bndl-io-use-local-storage/issues"},"homepage":"https://github.com/DatHuis/-bndl-io-use-local-storage#readme","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-tloumzkYGItE0Shw2ORkQ+G8XjrIGre2o41KYtjGcZm77QaPkYK+g4tM0hKp3x1Zt3imnfQdkUMecAxPec/Lqg==","shasum":"8d7820729929886ca958a47e5d7aea88b0a743f5","tarball":"https://registry.npmjs.org/@bndl-io/use-local-storage/-/use-local-storage-1.1.0.tgz","fileCount":11,"unpackedSize":11571,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB37LEISvGUfJyAIVeXCIUK72uJxsJ+ioEGunrotJU10AiEAkxM3OUAIjK4xmEhQrJIFDZ4kd/kxFFGi+zYdjOda8Go="}]},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"directories":{},"maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-local-storage_1.1.0_1733489610010_0.2468451044479758"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-04T14:18:28.483Z","modified":"2024-12-06T12:53:30.343Z","0.0.1":"2024-12-04T14:18:28.741Z","1.0.0":"2024-12-04T14:41:48.323Z","1.0.1":"2024-12-04T15:05:47.347Z","1.1.0":"2024-12-06T12:53:30.169Z"},"bugs":{"url":"https://github.com/DatHuis/-bndl-io-use-local-storage/issues"},"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","homepage":"https://github.com/DatHuis/-bndl-io-use-local-storage#readme","keywords":["react","hook","localstorage","typescript"],"repository":{"type":"git","url":"git+https://github.com/DatHuis/-bndl-io-use-local-storage.git"},"description":"A React hook to manage local storage values as state.","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"readme":"# @bndl-io/use-local-storage\n\nA TypeScript-friendly React hook for managing local storage values as component state, with compatibility for private or unsupported environments.\n\n## Installation\n\n```bash\nnpm install @bndl-io/use-local-storage\n```\n\n## Features\n\n- Simple interface to use local storage with React state management.\n- Supports environments where local storage is unavailable (e.g., private browsing mode).\n- Automatically syncs values across multiple tabs.\n- Allows setting an initial value which takes precedence over stored values.\n\n## Usage\n\nImport the hook and use it in your functional React component:\n\n```typescript\nimport useLocalStorageValue from '@bndl-io/use-local-storage';\n\nconst MyComponent: React.FC = () => {\n  const [name, setName] = useLocalStorageValue<string>('username', 'GuestUser');\n\n  return (\n    <div>\n      <input\n        type=\"text\"\n        value={name || ''}\n        onChange={e => setName(e.target.value)}\n        placeholder=\"Enter your name\"\n      />\n      <p>Your name is: {name}</p>\n    </div>\n  );\n};\n```\n\n### API\n\n```typescript\nconst [value, setValue] = useLocalStorageValue<T>(key: string, initialValue?: T): [T | null, (value: T) => void];\n```\n\n- **key**: `string` - The key to be used in local storage.\n- **initialValue**: `T` (optional) - The initial value to use if no value is found in local storage. This value takes precedence and will be saved to local storage on initialization.\n- **value**: `T | null` - The current value stored in local storage, parsed as an object.\n- **setValue**: `(value: T) => void` - Function to update the value in both local storage and state.\n\n### Example\n\n```typescript\nimport useLocalStorageValue from '@bndl-io/use-local-storage';\n\nconst MyCounterComponent: React.FC = () => {\n  const [counter, setCounter] = useLocalStorageValue<number>('counter', 0);\n\n  return (\n    <div>\n      <p>Counter: {counter}</p>\n      <button onClick={() => setCounter(prev => (prev ?? 0) + 1)}>\n        Increment\n      </button>\n    </div>\n  );\n};\n```\n\nThis hook can be used to persist and manipulate any serializable value in local storage.\n\n## Safe Storage Handling\n\nThe hook uses a `safeLocalStorage` implementation to ensure the code works even in environments where access to local storage may be restricted (such as private browsing).\n\n## License\n\nMIT\n","readmeFilename":"README.md"}