Documentation Index
Fetch the complete documentation index at: https://mintlify.com/LegendApp/legend-state/llms.txt
Use this file to discover all available pages before exploring further.
useWhen and useWhenReady are React hooks that create memoized promises which resolve when observables meet specific conditions.
Import
useWhen
Returns a promise that resolves when the predicate returns a truthy value.Signature
Parameters
A function that returns an observable value to check
Optional function to run when the predicate becomes truthy
Returns
Promise that resolves with the truthy value or the effect’s return value.useWhenReady
Returns a promise that resolves when the predicate returns a non-null/undefined value.Signature
Examples
Basic usage
With effect
Async component setup
Comparison
| Feature | useWhen | useWhenReady |
|---|---|---|
| Resolves when | Value is truthy | Value is not null/undefined |
| Useful for | Boolean conditions | Data loading |
| Example | isReady.get() === true | data.get() !== null |
Notes
- The promise is memoized and created only once during the component lifecycle
- Similar to
when()andwhenReady()but React-aware - Useful for coordinating async operations with observable state
Related
- when() - Core when function
- useMount() - Run effect on mount
- useObserve() - Observe changes