Skip to content

Commit

Permalink
docs: clarify getOnInit being false (#2391)
Browse files Browse the repository at this point in the history
* docs: clarify that getOnInit should be set to true in an SPA if you want the stored value on initialization

* docs: add backticks
  • Loading branch information
henrikvilhelmberglund authored Feb 11, 2024
1 parent 00c537f commit 358c39f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/utilities/storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The `atomWithStorage` function creates an atom with a value persisted in `localS

**options** (optional): an object with the following properties:

- **getOnInit** (optional): A boolean value indicating whether to get item from storage on initialization.
- **getOnInit** (optional, by default **false**): A boolean value indicating whether to get item from storage on initialization. Note that in an SPA with `getOnInit` either not set or `false` you will always get the initial value instead of the stored value on initialization. If the stored value is preferred set `getOnInit` to `true`.

If not specified, the default storage implementation uses `localStorage` for storage/retrieval, `JSON.stringify()`/`JSON.parse()` for serialization/deserialization, and subscribes to `storage` events for cross-tab synchronization.

Expand Down

0 comments on commit 358c39f

Please sign in to comment.