import { createWatch } from "effector";Methods
createWatch(config)
Creates a subscription on unit (store, event, or effect).
Formulae
createWatch<T>(config: {  unit: Unit<T>  fn: (payload: T) => void  scope?: Scope}): SubscriptionArguments
- config(Object): Configuration- unit(Unit): Target unit (store, event of effect) that will be watched
- fn(Function): Function that will be called when the unit is triggered. Accepts the unit’s payload as the first argument.
- scope(Scope): An optional scope object (forked instance) to restrict watcher calls on particular scope.
 
Returns
Subscription: Unsubscribe function
Examples
With scope
import { createWatch, createEvent, fork, allSettled } from "effector";
const changeName = createEvent();
const scope = fork();
const unwatch = createWatch({ unit: changeName, scope, fn: console.log });
await allSettled(changeName, { scope, params: "John" }); // output: JohnchangeName("John"); // no outputWithout scope
import { createWatch, createEvent, fork, allSettled } from "effector";
const changeName = createEvent();
const scope = fork();
const unwatch = createWatch({ unit: changeName, fn: console.log });
await allSettled(changeName, { scope, params: "John" }); // output: JohnchangeName("John"); // output: John