Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface UseAtomOptions<S, R>

Optional configuration accepted by useAtom

Type parameters

  • S

  • R

Hierarchy

  • UseAtomOptions

Index

Properties

Properties

select

select: function

A selector function to be applied to the internal state of the Atom to compute the return value of useAtom.

If the selector is known to be an expensive computation, you should consider passing a referentially stable, memoized version of the function.

example

import { Atom, useAtom } from '@dbeining/react-atom'
import { Orders } from 'elsewhere'

const stateAtom = Atom.of({ orders: [...Orders] })

function MyComponent() {
 const orderCount = useAtom(stateAtom, {
   select: (s) => s.orders.length
 })

 return <p>There are {orderCount} orders</p>
}

Type declaration

    • (s: S): R
    • Parameters

      • s: S

      Returns R