From bdc61c7822b91577979f4a8b42fec5e71806e0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Sat, 21 Dec 2024 13:18:29 +0100 Subject: [PATCH] Expanded svelte/reactivity documentation --- .../docs/98-reference/21-svelte-reactivity.md | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/documentation/docs/98-reference/21-svelte-reactivity.md b/documentation/docs/98-reference/21-svelte-reactivity.md index 6857c1dba80d..141c674b6678 100644 --- a/documentation/docs/98-reference/21-svelte-reactivity.md +++ b/documentation/docs/98-reference/21-svelte-reactivity.md @@ -22,4 +22,85 @@ Svelte provides reactive versions of various built-ins like `SvelteMap`, `Svelte ``` +The utilities provided in `svelte/reactivity` are automatically reactive with respect to their properties and methods, as seen in the previous example. As such, they don't need to be wrapped in `$state`. However, if a variable is reassigned, it needs to be wrapped in a `$state` in order for this reassignement to be reactive. + +```svelte + + + +Protocol: {url?.protocol ?? "ftp:"} +
+Hostname: {url?.hostname ?? "svelte.dev"} +
+Path: {url?.pathname ?? ""} + +
+ + + +``` + +In a similar manner, the values stored inside e.g. `SvelteMap` are not automatically reactive, so if more complex values such as objects are used, they need to be wrapped in a `$state` in order to make their properties reactive as well. + +```svelte + + +{#each people.entries() as [id, person] (id)} + Name: {person.name} +
+ Age: {person.age} +
+
+{/each} + +
+ + + + + + + + + +``` + > MODULE: svelte/reactivity