react-native-onyx
Version:
State management for React Native
27 lines (26 loc) • 1.58 kB
TypeScript
import type { DependencyList } from 'react';
import type { OnyxKey, OnyxValue } from './types';
type UseOnyxSelector<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>> = (data: OnyxValue<TKey> | undefined) => TReturnValue;
type UseOnyxOptions<TKey extends OnyxKey, TReturnValue> = {
/**
* If set to `false`, the connection won't be reused between other subscribers that are listening to the same Onyx key
* with the same connect configurations.
*/
reuseConnection?: boolean;
/**
* This will be used to subscribe to a subset of an Onyx key's data.
* Using this setting on `useOnyx` can have very positive performance benefits because the component will only re-render
* when the subset of data changes. Otherwise, any change of data on any property would normally
* cause the component to re-render (and that can be expensive from a performance standpoint).
* @see `useOnyx` cannot return `null` and so selector will replace `null` with `undefined` to maintain compatibility.
*/
selector?: UseOnyxSelector<TKey, TReturnValue>;
};
type FetchStatus = 'loading' | 'loaded';
type ResultMetadata = {
status: FetchStatus;
};
type UseOnyxResult<TValue> = [NonNullable<TValue> | undefined, ResultMetadata];
declare function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey, options?: UseOnyxOptions<TKey, TReturnValue>, dependencies?: DependencyList): UseOnyxResult<TReturnValue>;
export default useOnyx;
export type { FetchStatus, ResultMetadata, UseOnyxResult, UseOnyxOptions, UseOnyxSelector };