4.0.2 • Published 3 years ago

@respite/select v4.0.2

Weekly downloads
98
License
MIT
Repository
github
Last release
3 years ago

@respite/select

A simple selector hook for queries and atoms

This will just cover getting started and the api, for an overarching explanation of respite, see the repo readme

Getting started

npm install @respite/core @respite/select

Usage

const derivedQuery = useSelector(query, (state) => state.someProperty);
const derivedAtom = useSelector(myAtom, (state) => state.someProperty);

useSelector

<T, R>(query: Query<T>, selector(t: T) => R, deps?: any[]): Query<R>
<T, R>(atom: Atom<T>, selector(t: T) => R,deps?: any[]): R;

For queries it returns a derived query using the selector function. The derived query is also lazy.

For atoms, the selector just immediately returns the derived value. In theory there isn't much difference between writing a selector or using a molecule to derive state from another atom. But often in practice a selector is much quicker to quickly set up for a one-off use.

useSelectAll

<T, R>(queries: Array<Query<T>>, selector(...t: T[]) => R, deps?: any[]): Query<R>
<T, R>(atoms: Array<Atom<T>>, selector(...t: T[]) => R,deps?: any[]): R;

Similar to useSelector but accepts an array of queries/atoms.

Only an array of atoms or an array of molecules is accounted for. Mixing atoms and molecules is not supported currently

useSelectValue

<T, R>(query: Query<T>, selector(t: T) => R, deps?: any[]): R;
<T, R>(atom: Atom<T>, selector(t: T) => R,deps?: any[]): R;

Similar to useSelector except it immediately returns the transformed value instead of returning a query object

4.0.2

3 years ago

4.0.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.8.0

3 years ago

2.7.0

3 years ago

2.7.1

3 years ago

2.5.1

3 years ago

2.5.0

3 years ago

2.2.0

3 years ago

2.4.0

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago