From d77b62d63ee16d30f628b49cfd657204d0e1fa13 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 21 Jul 2022 09:56:01 +0100 Subject: [PATCH] docs: warn that `useState` should only contain JSON-serializable content (#5994) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pooya parsa Co-authored-by: Damian Głowala <48835293+DamianGlowala@users.noreply.github.com> Co-authored-by: Alwin Lohrie <46248939+niwla23@users.noreply.github.com> --- docs/content/2.guide/2.features/6.state-management.md | 3 +++ docs/content/3.api/1.composables/use-state.md | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/docs/content/2.guide/2.features/6.state-management.md b/docs/content/2.guide/2.features/6.state-management.md index 727064711c..f1f83bcb2e 100644 --- a/docs/content/2.guide/2.features/6.state-management.md +++ b/docs/content/2.guide/2.features/6.state-management.md @@ -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 diff --git a/docs/content/3.api/1.composables/use-state.md b/docs/content/3.api/1.composables/use-state.md index 30ac7d5c4e..f854881b32 100644 --- a/docs/content/3.api/1.composables/use-state.md +++ b/docs/content/3.api/1.composables/use-state.md @@ -9,5 +9,9 @@ useState(key: string, init?: () => T | Ref): Ref * **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"} ::