![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@illinois/react-use-local-storage
Advanced tools
React hook that persists and syncs state with local storage
React hook that persists state with the localStorage
API. It also automatically syncs state between tabs/windows.
npm i @illinois/react-use-local-storage
This hook functions similarly to useState
, with the exception of the the caveats listed below. If your state is easily encodable in JSON and you don't use lazy initialization or functional updates, it should be easy to migrate from useState
. You'll need to provide a key for getting/setting the item in local storage.
import useLocalStorage from '@illinois/react-use-local-storage'
const MyComponent = () => {
const [count, setCount] = useLocalStorage('value-key', 0)
return (
<>
<div>Count: {count}</div>
<button onClick={() => setCount(count + 1)}>Increase</button>
<button onClick={() => setCount(0)}>Reset</button>
</>
)
}
git clone https://github.com/illinois/react-use-local-storage.git react-use-local-storage
cd react-use-local-storage
npm install
npm run storybook
This will launch a simple demo with a counter that can be incremented and reset. Try opening the demo in two tabs at once and watch how changes are automatically synced between them!
State is serialized with JSON.stringify
and deserialized with JSON.parse
. This is done because the localStorage
API doesn't support storing anything but strings at present. As such, you should pay special attention to objects that might not handle being round-tripped through JSON, e.g. a Date
object.
Unlike useState
, lazy initialization is not currently supported. A PR adding support would be welcome!
Unlike useState
, functional updates are not currently supported. A PR adding support would be welcome!
FAQs
React hook that persists and syncs state with local storage
The npm package @illinois/react-use-local-storage receives a total of 40 weekly downloads. As such, @illinois/react-use-local-storage popularity was classified as not popular.
We found that @illinois/react-use-local-storage 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.