neux - v0.17.3
    Preparing search index...

    Function signal

    • Creates a reactive proxy around the given data object.

      Property reads inside an active effect are automatically tracked. Writes and deletions schedule a debounced re-run of dependent effects.

      Type Parameters

      • T extends Record<PropertyKey, any> = Record<PropertyKey, any>

        The initial data type. Defaults to a plain object.

      Parameters

      • this: void | object

        Reactive context; defaults to the shared global context when called without an explicit receiver. To isolate signals, bind or call with a custom object: signal.call(myCtx, data).

      • data: T = ...

        The initial data. Defaults to an empty plain object.

      Returns T

      A reactive Proxy that mirrors data, preserving array vs object shape.

      // creates a reactive signal
      const state = signal({
      // reactive field
      page: 1,
      // computed reactive field
      get left() {
      return 100 - this.page;
      },
      // non-reactive methods
      nextPost() {
      if (this.page < 100) this.page++;
      },
      prevPost() {
      if (this.page > 0) this.page--;
      },
      async fetchPost() {
      const response = await fetch(
      `https://jsonplaceholder.typicode.com/posts/${this.page}`,
      );
      return await response.json();
      },
      });