Cookbook / Theme Toggle

Theme Toggle

display

Theme switcher — state-backed theme is provided to descendants and mirrored onto documentElement by an effect.

id
theme-toggle
since
0.5.0
file
theme-toggle.aihu
stateprovideeffectactionon:clickinterpolation

Run it

source · static

This recipe doesn't have a hydrated island in the demo gallery yet. An in-browser, WASM-compiled playground (edit this source and re-render live) is planned as a follow-up — read the real source below.

Source

theme-toggle.aihu

Requires

concerns
stylingstate

Anti-patterns

  • Do not toggle document-level classes inside action bodies — the effect() re-runs whenever theme changes, keeping DOM and state in sync from one place.

Related recipes