Reactive utilities

on

Edit this page

Replacement: split effects

The on helper was designed to make effect dependencies explicit. In Solid 2.0, the split effect model achieves this naturally:

// 1.x — using on() for explicit dependencies
import { on, createEffect } from "solid-js"
createEffect(on(a, (v) => console.log(v, b())))
// 2.0 — compute function declares dependencies, apply runs the side effect
createEffect(
() => a(), // compute: explicitly track only `a`
(v) => console.log(v, b()) // apply: `b` is not tracked
)

Deferred execution

The defer option that prevented the first run is no longer needed — effects in Solid 2.0 are already deferred by default (scheduled after the rendering phase).

Multiple dependencies

// 1.x
createEffect(on([a, b], ([aVal, bVal]) => console.log(aVal, bVal)))
// 2.0
createEffect(
() => [a(), b()],
([aVal, bVal]) => console.log(aVal, bVal)
)
Report an issue with this page