From f40efb2027fca454aff409466433f25d1bffbf02 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 22 Nov 2023 15:00:24 -0500 Subject: [PATCH] `$effect.active` docs (#9598) * docs: $effect.active * link --------- Co-authored-by: Rich Harris --- .../src/routes/docs/content/01-api/02-runes.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md b/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md index d8da797c7..47017d1a0 100644 --- a/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md +++ b/sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md @@ -168,6 +168,24 @@ In rare cases, you may need to run code _before_ the DOM updates. For this we ca Previously, you would have used `beforeUpdate`, which — like `afterUpdate` — is deprecated in Svelte 5. +## `$effect.active` + +The `$effect.active` rune is an advanced feature that tells you whether or not the code is running inside an effect or inside your template ([demo](/#H4sIAAAAAAAAE3XP0QrCMAwF0F-JRXAD595rLfgdzodRUyl0bVgzQcb-3VYFQfExl5tDMgvrPCYhT7MI_YBCiiOR2Aq-UxnSDT1jnlOcRlMSlczoiHUXOjYxpOhx5-O12rgAJg4UAwaGhDyR3Gxhjdai4V1v2N2wqus9tC3Y3ifMQjbehaqq4aBhLtEv_Or893icCsdLve-Caj8nBkU67zMO5HtGCfM3sKiWNKhV0zwVaBqd3x3ixVmHFyFLuJyXB-moOe8pAQAA)): + +```svelte + + +

in template: {$effect.active()}

+``` + +This allows you to (for example) add things like subscriptions without causing memory leaks, by putting them in child effects. + ## `$props` To declare component props, use the `$props` rune: