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

Co-authored-by: pooya parsa <pyapar@gmail.com>
Co-authored-by: Damian Głowala <48835293+DamianGlowala@users.noreply.github.com>
Co-authored-by: Alwin Lohrie <46248939+niwla23@users.noreply.github.com>
This commit is contained in:
Daniel Roe 2022-07-21 09:56:01 +01:00 committed by GitHub
parent 92269dde44
commit d77b62d63e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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"}
::