Skip to content

Function: watch()

watch<State, S, R>(path, adapter?): ReactWatch<State, S>

Defined in: lib/watch.function.ts:31

See StateAdapt.watch for the complete API.

This wrapper additionally lets you call the store as a function for its current state, or call a selector property for its current result.

ts
import { stringAdapter } from '@state-adapt/core/adapters';
import { watch } from '@state-adapt/react';

const name = watch('name', stringAdapter);

// While the store at "name" is active:
console.log(name()); // 'John'
console.log(name.uppercase()); // 'JOHN'

Reads are undefined while the store is inactive and do not activate its sources. See derive for composing these reads.

Type Parameters

State

State = any

S

S extends Selectors<State> = { }

R

R extends ReactionsWithSelectors<State, S> = { }

Parameters

path

string

adapter?

Adapter<State, S, R & BasicAdapterMethods<State>>

Returns

ReactWatch<State, S>