Skip to content

Run a side effect that re-executes when its signal dependencies change. See How Reactivity Works for the underlying mental model.

function effect(fn: () => void | (() => void)): () => void
ParamTypeDescription
fn() => void | (() => void)Effect function. Can return a cleanup function.

() => void — dispose function that stops the effect.

import { signal, effect } from "@whisq/core";
const count = signal(0);
const dispose = effect(() => {
console.log(`Count: ${count.value}`);
});
// Logs: "Count: 0"
count.value = 1; // Logs: "Count: 1"
dispose(); // Stop watching
count.value = 2; // No log
effect(() => {
const timer = setInterval(() => tick(), 1000);
return () => clearInterval(timer);
});
  • signal() — the mutable primitive; effect() re-runs when a tracked signal changes.
  • computed() — derived values; prefer over effect() when you need a readable result.
  • onCleanup() — component-scoped cleanup for effects started inside a component.
  • batch() — batch multiple writes into one effect re-run.

Docs current to v0.1.0-alpha.9 . All releases →