Skip to content

Commit

Permalink
✏️ improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Sep 6, 2024
1 parent 9d74ea6 commit 42f2aba
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,27 @@ The default value. You can think of it as the same as `useState(defaultValue)`.

#### `options.storage`

Type: `"local" | "session" | Storage`
Type: `"local" | "session" | Storage | undefined`

Default: `"local"`

You can set `localStorage`, `sessionStorage`, or other any [`Storage`](https://developer.mozilla.org/en-US/docs/Web/API/Storage) compatible class.

_Note:_ Prefer to use the `"local"` and `"session"` literals instead of `localStorage` or `sessionStorage` objects directly, as both can throw an error when accessed if user has configured the browser to not store any site data.

```ts
const [multiplier, setMultiplier] = useStorageState('multiplier', {
storage: "session" // default is "local"
})
```

#### `options.memoryFallback`

Type: `boolean`

Default: `true`

If `localStorage` or `sessionStorage` throw an error when accessed (possible when the browser is configured to not store any site data on device), the library uses a memory storage fallback to at least allow for the hook to be functional. You can disable this behavior by setting this option to `false`.
If you pass `undefined` to the `storage` option or `localStorage` or `sessionStorage` throw an error when accessed (possible when the browser is configured to not store any site data on device), the library uses a memory storage fallback to avoid your app from breaking completely. You can disable this behavior by setting this option to `false`.

#### `options.sync`

Expand Down

0 comments on commit 42f2aba

Please sign in to comment.