use-local-storage-state
Advanced tools
Comparing version 9.0.1 to 9.0.2
{ | ||
"name": "use-local-storage-state", | ||
"version": "9.0.1", | ||
"version": "9.0.2", | ||
"description": "React hook that persist data in local storage. Done right.", | ||
@@ -36,24 +36,2 @@ "license": "MIT", | ||
}, | ||
"size-limit": [ | ||
{ | ||
"name": "import *", | ||
"path": "es/index.js", | ||
"limit": "2 KB", | ||
"gzip": false | ||
}, | ||
{ | ||
"name": "import { useLocalStorageState }", | ||
"path": "es/index.js", | ||
"import": "{ useLocalStorageState }", | ||
"limit": "1.6 KB", | ||
"gzip": false | ||
}, | ||
{ | ||
"name": "import { createLocalStorageState }", | ||
"path": "es/index.js", | ||
"import": "{ createLocalStorageStateHook }", | ||
"limit": "1.6 KB", | ||
"gzip": false | ||
} | ||
], | ||
"engines": { | ||
@@ -66,3 +44,4 @@ "node": ">=10" | ||
"index.d.ts", | ||
"src/*.d.ts" | ||
"src/*.d.ts", | ||
"es/**/*.js" | ||
], | ||
@@ -97,3 +76,25 @@ "peerDependencies": { | ||
"typescript": "^4.1.3" | ||
} | ||
}, | ||
"size-limit": [ | ||
{ | ||
"name": "import *", | ||
"path": "es/index.js", | ||
"limit": "2 KB", | ||
"gzip": false | ||
}, | ||
{ | ||
"name": "import { useLocalStorageState }", | ||
"path": "es/index.js", | ||
"import": "{ useLocalStorageState }", | ||
"limit": "1.6 KB", | ||
"gzip": false | ||
}, | ||
{ | ||
"name": "import { createLocalStorageState }", | ||
"path": "es/index.js", | ||
"import": "{ createLocalStorageStateHook }", | ||
"limit": "1.6 KB", | ||
"gzip": false | ||
} | ||
] | ||
} |
@@ -7,3 +7,2 @@ # `use-local-storage-state` | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/38dfdf48f7f326ccfa8e/test_coverage)](https://codeclimate.com/github/astoilkov/use-local-storage-state/test_coverage) | ||
[![Minified Size](https://badgen.net/bundlephobia/min/use-local-storage-state)](https://bundlephobia.com/result?p=use-local-storage-state) | ||
![Dependencies](https://david-dm.org/astoilkov/use-local-storage-state.svg) | ||
@@ -26,2 +25,5 @@ | ||
- Subscribes to the Window [`storage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event) event which tracks changes across browser tabs and iframe's | ||
- Small. Controlled by `size-limit`. | ||
- `import { useLocalStorageState } from 'use-local-storage-state'` 1.55 kB | ||
- `import { createLocalStorageState } from 'use-local-storage-state'` 1.5 kB | ||
- High quality with [my open-source principles](https://github.com/astoilkov/me/blob/master/essays/My%20open-source%20principles.md) | ||
@@ -67,2 +69,17 @@ | ||
### Reseting to defaults | ||
The `setTodos.reset()` method will reset the value to its default and will remove the key from the `localStorage`. It returns to the same state as when the hook was initially created. | ||
```tsx | ||
import useLocalStorageState from 'use-local-storage-state' | ||
const [todos, setTodos] = useLocalStorageState('todos', [ | ||
'buy milk', | ||
'do 50 push-ups' | ||
]) | ||
setTodos.reset() | ||
``` | ||
### Handling edge cases with `isPersistent` | ||
@@ -89,17 +106,2 @@ | ||
### Reseting to defaults | ||
The `setTodos.reset()` method will reset the value to its default and will remove the key from the `localStorage`. It returns to the same state as when the hook was initially created. | ||
```tsx | ||
import useLocalStorageState from 'use-local-storage-state' | ||
const [todos, setTodos] = useLocalStorageState('todos', [ | ||
'buy milk', | ||
'do 50 push-ups' | ||
]) | ||
setTodos.reset() | ||
``` | ||
## API | ||
@@ -106,0 +108,0 @@ |
26318
18
412
172