
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@plq/use-persisted-state
Advanced tools
Persists the state to localStorage, sessionStorage or anything else that implements getItem
, setItem
and removeItem
localStorage
, sessionStorage
or anything else that implements getItem
, setItem
and removeItem
import createPersistedState from '@plq/use-persisted-state'
const [usePersistedState] = createPersistedState('example')
export default function App() {
const [count, setCount] = usePersistedState('count', 0)
const handleIncrement = () => setCount(prevCount => prevCount + 1)
return (
<div>
{count}
<button onClick={handleIncrement}>+</button>
</div>
)
}
Little bit closer to real life:
To use @plq/use-persisted-state
, you must use react@16.8.0
or greater which includes Hooks.
import createPersistedState from '@plq/use-persisted-state'
const [usePersistedState, clear] = createPersistedState('example')
export default function App() {
const [count, setCount] = usePersistedState('count', 0)
const increment = () => setCount(prevCount => prevCount + 1)
return (
<div>
{count}
<button onClick={increment}>+</button>
<button onClick={clear}>Clear</button>
</div>
)
}
import createPersistedState from '@plq/use-persisted-state'
const [usePersistedState] = createPersistedState('example', window.sessionStorage)
export default function App() {
const [count, setCount] = usePersistedState('count', 0)
const increment = () => setCount(prevCount => prevCount + 1)
return (
<div>
{count}
<button onClick={increment}>+</button>
</div>
)
}
import createPersistedState from '@plq/use-persisted-state'
const myStorage = {
getItem: (key) => getItemFromSomeStorage(key)
setItem: (key, value) => setItemToSomeStorage(key, value)
removeItem: (key) => removeItemFromSomeStorage(key)
}
const [usePersistedState] = createPersistedState('example', myStorage)
export default function App() {
const [count, setCount] = usePersistedState('count', 0)
const increment = () => setCount(prevCount => prevCount + 1)
return (
<div>
{count}
<button onClick={increment}>+</button>
</div>
)
}
FAQs
useState hook with persistence in storage
The npm package @plq/use-persisted-state receives a total of 484 weekly downloads. As such, @plq/use-persisted-state popularity was classified as not popular.
We found that @plq/use-persisted-state demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.