Skip to content

Svelte 5: Document when not to use $effect #10193

@dummdidumm

Description

@dummdidumm

Describe the problem

People tend to overuse $effect. We should make it clear in the documentation when to actually use it, and when to use other things instead.
This doesn't need to be on the preview docs but should certainly be part of the final docs.

Describe the proposed solution

If we have a more general guide for runes, describe how to ensure reactivity in various ways and try to avoid mentioning $effect as much as possible.

In the API section, within $effect, start by saying that you likely don't need $effect:

  • If you want something to update in reaction to something else, use $derived
  • If you want to have something update from above but also modify it from below (i.e. you want some kind of "writable $derived"), use an object with getters and setters instead (no glitches/dangers of infinite loops, works in SSR)
  • other use cases I can't think of right now that are common

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions