neux - v0.17.3
    Preparing search index...

    Function effect

    • Creates a reactive effect that re-runs whenever tracked properties change.

      The getter function is executed immediately. Any property read on a signal during this execution is subscribed to the effect. When a subscribed property is written, the effect is scheduled to re-run (debounced via setTimeout 0).

      An optional setter receives the return value of getter. When the getter returns a Promise, setter is called with its resolved value.

      The context is determined by this, following the same rules as signal.

      Parameters

      • this: void | object

        Reactive context; defaults to the shared global context.

      • getter: () => any

        Function that reads reactive properties and optionally returns a value.

      • Optionalsetter: (value: any) => void

        Optional callback that receives the return value of getter, or its resolved value when getter returns a promise.

      Returns () => void

      A disposal function that unsubscribes the effect from all tracked properties.

      // creates a reactive signal
      const state = signal({ count: 0 });
      // subscribes to changes
      const dispose = effect(() => {
      // read with subscription
      console.log(state.count);
      });
      // triggers the effect
      state.count += 1;
      // later …
      dispose();