UNPKG

@ewb/reach-react

Version:
18 lines (17 loc) 842 B
import { Dispatch, SetStateAction } from 'react'; import { IReachOptions } from '@ewb/reach'; import type { IUseProps } from './types'; export interface IUseReachProps<T> extends IUseProps<T> { } export interface IUseReachState<T, E> { busy: boolean; data?: T; error?: E; } export declare type IUseReachFetch<T> = <M extends IReachOptions['method']>(method: M, id: M extends 'PATCH' | 'DELETE' ? string : Partial<T>, body?: M extends 'PATCH' ? Partial<T> : undefined) => Promise<T | null>; export declare type IUseReachRet<T, E> = [ state: IUseReachState<T, E>, fetch: IUseReachFetch<T>, setState: Dispatch<SetStateAction<IUseReachState<T, E>>> ]; export declare function useReach<T, E = any>(path: string, props?: IUseReachProps<T>, reachOptions?: Omit<IReachOptions, 'method'>): IUseReachRet<T, E>;