New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

use-local-storage-state

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-local-storage-state - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

5

package.json
{
"name": "use-local-storage-state",
"version": "1.0.0",
"version": "1.0.1",
"description": "React hook for local storage state done right",

@@ -34,3 +34,4 @@ "license": "MIT",

"files": [
"dist/index.js"
"dist/index.js",
"dist/index.d.ts"
],

@@ -37,0 +38,0 @@ "peerDependencies": {

66

readme.md

@@ -23,2 +23,3 @@ # `use-local-storage-state`

- Used in a production application which is based on [Caret - Markdown Editor for Mac / Windows](https://caret.io/) and is in private beta.
- Supports creating a global hook that can be used in multiple places. See the last example in the **Usage** section.

@@ -28,2 +29,4 @@ ## Usage

```typescript
import useLocalStorageState from 'use-local-storage-state'
const [todos, setTodos] = useLocalStorageState('todos', [

@@ -57,2 +60,63 @@ 'buy milk',

```
```
Using the same data from the storage in multiple places:
```typescript
import { createLocalStorageStateHook } from 'use-local-storage-state'
// store.ts
export const useTodos = createLocalStorageStateHook('todos', [
'buy milk',
'do 50 push-ups'
])
// Todos.ts
function Todos() {
const [todos, setTodos] = useTodos()
}
// Popup.ts
function Popup() {
const [todos, setTodos] = useTodos()
}
```
## API
### useLocalStorageState(key, defaultValue?)
Returns the same value that React `useState()` returns.\
Look at **Usage** section for an example.
#### key
Type: `string`
The key that will be used when calling `localStorage.setItem(key)`and `localStorage.getItem(key)`.\
⚠️ Be careful with name conflicts as it is possible to access a property which is already in `localStorage` that was created from another place in the codebase or in an old version of the application.
#### defaultValue
Type: `any`
Default: `undefined`
The initial value of the data. The same as `useState(defaultValue)` property.
### createLocalStorageStateHook(key, defaultValue?)
Returns a hook to be used in multiple places.\
Look at **Usage** section for an example.
#### key
Type: `string`
The key that will be used when calling `localStorage.setItem(key)`and `localStorage.getItem(key)`.\
⚠️ Be careful with name conflicts as it is possible to access a property which is already in `localStorage` that was created from another place in the codebase or in an old version of the application.
#### defaultValue
Type: `any`
Default: `undefined`
The initial value of the data. The same as `useState(defaultValue)` property.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc