werkbank
    Preparing search index...

    Function selector

    • Creates a selector to derive state from multiple atoms.

      Type Parameters

      • A extends Atom<any, any>[]

        The array of input atoms.

      • R

        The return type of the selector.

      Parameters

      • atoms: [...A[]]

        The input atoms.

      • callback: (...values: [...AtomValues<A>[]]) => R

        The function to compute the derived state.

      Returns Selector<A, R>

      A selector definition object.

      Selectors allow you to compute derived state that updates whenever any of the input atoms change.

      const sumSelector = selector([atomA, atomB], (a, b) => a + b);