qortex-react
Version:
React hook bridge for qortex runtime
46 lines (41 loc) • 1.97 kB
TypeScript
import { Fetcher, QueryKey, QueryOptions, InferFetcherResult, QueryState } from 'qortex-core';
export * from 'qortex-core';
/**
* useQuery hook for React integration with qortex
* Provides reactive data fetching with automatic re-renders on state changes
* Enhanced with automatic type inference from fetchers
*/
declare function useQuery<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
fetcher: F;
}): QueryState<InferFetcherResult<F>>;
declare function useQuery<T = any>(key: QueryKey, opts?: QueryOptions<T>): QueryState<T>;
/**
* useQueryData hook for React integration with qortex
* Provides reactive data fetching with automatic re-renders on state changes
* Enhanced with automatic type inference from fetchers
*/
declare function useQueryData<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
fetcher: F;
}): InferFetcherResult<F> | undefined;
declare function useQueryData<T = any>(key: QueryKey, opts?: QueryOptions<T>): T | undefined;
/**
* useQuerySelect hook for React integration with qortex
* Provides reactive data fetching with automatic re-renders on state changes
* Enhanced with automatic type inference from fetchers
*
* Now includes smart subscription: automatically detects which properties are accessed
* and only re-renders when those specific properties change, not the entire state.
*
* @example
* ```tsx
* const query = useQuerySelect('users', { fetcher: fetchUsers });
*
* // Only re-renders when data or isSuccess changes, not when isError changes
* return <div>{query.isSuccess ? query.data?.name : 'Loading...'}</div>;
* ```
*/
declare function useQuerySelect<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
fetcher: F;
}): QueryState<InferFetcherResult<F>>;
declare function useQuerySelect<T = any>(key: QueryKey, opts?: QueryOptions<T>): QueryState<T>;
export { useQuery, useQueryData, useQuerySelect };