Gathering detailed insights and metrics for @plq/use-persisted-state
Gathering detailed insights and metrics for @plq/use-persisted-state
Gathering detailed insights and metrics for @plq/use-persisted-state
Gathering detailed insights and metrics for @plq/use-persisted-state
npm install @plq/use-persisted-state
Typescript
Module System
Min. Node Version
Node Version
NPM Version
68.2
Supply Chain
92.6
Quality
79.6
Maintenance
100
Vulnerability
100
License
TypeScript (88.77%)
JavaScript (11.23%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
97,427
Last Day
2
Last Week
356
Last Month
1,699
Last Year
25,209
MIT License
20 Stars
748 Commits
7 Forks
4 Watchers
2 Branches
4 Contributors
Updated on Sep 05, 2025
Latest Version
1.3.0
Package Id
@plq/use-persisted-state@1.3.0
Unpacked Size
63.42 kB
Size
14.28 kB
File Count
78
NPM Version
11.5.1
Node Version
24.5.0
Published on
Aug 02, 2025
Cumulative downloads
Total Downloads
Last Day
-66.7%
2
Compared to previous day
Last Week
6.6%
356
Compared to previous week
Last Month
-30.6%
1,699
Compared to previous month
Last Year
26%
25,209
Compared to previous year
1
28
Persists the state to localStorage, sessionStorage or any custom storage
localStorage
, sessionStorage
or almost anything else implements storage API1import createPersistedState from '@plq/use-persisted-state' 2import storage from '@plq/use-persisted-state/lib/storages/local-storage' 3 4const [usePersistedState] = createPersistedState('example', storage) 5 6export default function App() { 7 const [count, setCount] = usePersistedState('count', 0) 8 const handleIncrement = () => setCount(prevCount => prevCount + 1) 9 10 return ( 11 <div> 12 {count} 13 <button onClick={handleIncrement}>+</button> 14 </div> 15 ) 16}
To use @plq/use-persisted-state
, you must use react@16.8.0
or greater which includes Hooks.
The library is fully compatible with React 18 and React 19.
This library is fully compatible with React 19 and supports all new features:
useTransition
for performance optimizationuseActionState
for form handlinguseOptimistic
for optimistic updatesCheck out our React 19 examples to see these features in action!
1import createPersistedState from '@plq/use-persisted-state' 2import storage from '@plq/use-persisted-state/lib/storages/local-storage' 3 4const [usePersistedState, clear] = createPersistedState('example', storage) 5 6export default function App() { 7 const [count, setCount] = usePersistedState('count', 0) 8 const increment = () => setCount(prevCount => prevCount + 1) 9 10 return ( 11 <div> 12 {count} 13 <button onClick={increment}>+</button> 14 <button onClick={clear}>Clear</button> 15 </div> 16 ) 17}
1import createPersistedState from '@plq/use-persisted-state' 2import storage from '@plq/use-persisted-state/lib/storages/session-storage' 3 4const [usePersistedState, clear] = createPersistedState('example', storage)
1import createPersistedState from '@plq/use-persisted-state' 2// or 3import { createAsyncPersistedState } from '@plq/use-persisted-state' 4import { local } from '@plq/use-persisted-state/lib/storages/browser-storage' 5 6const [usePersistedState, clear] = createPersistedState('example', local)
The storage API is similar to the browser.storage but with a few differences
1import createPersistedState from '@plq/use-persisted-state'
2
3const storageListeners = new Set()
4
5onChangeSomeStorage(event => {
6 const changes = {
7 [event.key]: {
8 newValue: event.newValue,
9 oldValue: event.oldValue,
10 },
11 }
12
13 listeners.forEach(listener => {
14 listener(changes)
15 })
16})
17
18const myStorage = {
19 get: keys => getItemsFromSomeStorage(keys),
20 set: items => setItemsToSomeStorage(items),
21 remove: keys => removeItemsFromSomeStorage(keys),
22 onChanged: {
23 addListener: listener => storageListeners.add(listener),
24 removeListener: listener => storageListeners.delete(listener),
25 hasListener: listener => storageListeners.has(listener),
26 }
27}
28
29const [usePersistedState, clear] = createPersistedState('example', myStorage)
@plq/use-persisted-state/lib/storages/local-storage
@plq/use-persisted-state/lib/storages/session-storage
@plq/use-persisted-state/lib/storages/browser-storage
manifest.json
file@plq/use-persisted-state/lib/storages/chrome-storage
No vulnerabilities found.