Skip to content

Commit

Permalink
docs: update useLocalStorageValue and useSessionStorageValue stories
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed May 15, 2021
1 parent 19c727f commit cff404d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
24 changes: 13 additions & 11 deletions stories/SideEffects/useLocalStorageValue.story.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import {ArgsTable, Canvas, Meta, Story} from "@storybook/addon-docs/blocks";

Manages a single LocalStorage key.

- Uses JSON serialisation to handle non-string values.
- Tracks window's `storage` event.
- Synchronized between all hooks on the page managing same key.
- SSR compatible.

> **_This hook provides stable API, meaning returned methods does not change between renders_**
> This hook uses `useSafeState` underneath, so it is safe to use its `setState` in async hooks.
> Does not allow usage of `null` value, since JSON allows serializing `null` values - it would be
> Does not allow usage of `null` value, since JSON allows serializing `null` values - it would be
impossible to separate null value fom 'no such value' API result which is also `null`.

> By default, tracks window's `storage` event and automatically synchronizes all hooks on the page
managing same key.

> While using SSR, to avoid hydration mismatch, consider setting `initializeWithStorageValue` option to
`false`, this will yield `undefined` state on first render and defer value fetch to effects
execution stage.
Expand Down Expand Up @@ -49,13 +51,13 @@ function useLocalStorageValue<T>(
- **defaultValue** _`T | null`_ _(default: null)_ - Default value to return in case key not
presented in LocalStorage.
- **options** _`object`_ - Hook options:
- **isolated** _`boolean`_ _(default: false)_ - Disable synchronisation with other hook instances
managing same key on same page.
- **handleStorageEvent** _`boolean`_ _(default: true)_ - Subscribe to window's `storage` event.
- **storeDefaultValue** _`boolean`_ _(default: false)_ - store default value.
- **initializeWithStorageValue** _`boolean`_ _(default: true)_ - fetch storage value on first
render. If set to `false` will make hook to yield `undefined` state on first render and defer
value fetch till effects execution stage.
- **isolated** _`boolean`_ _(default: false)_ - Disable synchronisation with other hook instances
managing same key on same page.
- **handleStorageEvent** _`boolean`_ _(default: true)_ - Subscribe to window's `storage` event.
- **storeDefaultValue** _`boolean`_ _(default: false)_ - store default value.
- **initializeWithStorageValue** _`boolean`_ _(default: true)_ - fetch storage value on first
render. If set to `false` will make hook to yield `undefined` state on first render and defer
value fetch till effects execution stage.

#### Return

Expand Down
8 changes: 5 additions & 3 deletions stories/SideEffects/useSessionStorageValue.story.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import {ArgsTable, Canvas, Meta, Story} from "@storybook/addon-docs/blocks";

Manages a single SessionStorage key.

- Uses JSON serialisation to handle non-string values.
- Tracks window's `storage` event.
- Synchronized between all hooks on the page managing same key.
- SSR compatible.

> **_This hook provides stable API, meaning returned methods does not change between renders_**
> This hook uses `useSafeState` underneath, so it is safe to use its `setState` in async hooks.
> Does not allow usage of `null` value, since JSON allows serializing `null` values - it would be
impossible to separate null value fom 'no such value' API result which is also `null`.

> By default, tracks window's `storage` event and automatically synchronizes all hooks on the page
managing same key.

> While using SSR, to avoid hydration mismatch, consider setting `initializeWithStorageValue` option to
`false`, this will yield `undefined` state on first render and defer value fetch to effects
execution stage.
Expand Down

0 comments on commit cff404d

Please sign in to comment.