Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

docs: warn that useState should only contain JSON-serializable content #5994

Merged
merged 6 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/content/2.guide/2.features/6.state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Nuxt provides `useState` composable to create a reactive and SSR-friendly shared
::alert{icon=πŸ‘‰}
`useState` only works during `setup` or [`Lifecycle Hooks`](https://vuejs.org/api/composition-api-lifecycle.html#composition-api-lifecycle-hooks).
::
::alert{type=warning}
Because the data inside `useState` will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
::

## Best practices

Expand Down
4 changes: 4 additions & 0 deletions docs/content/3.api/1.composables/use-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ useState<T>(key: string, init?: () => T | Ref<T>): Ref<T>
* **init**: A function that provides initial value for the state when not initiated. This function can also return a `Ref`.
* **T**: (typescript only) Specify the type of state

::alert{type=warning}
Because the data inside `useState` will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
::

::ReadMore{link="/guide/features/state-management"}
::