UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

22 lines (21 loc) 953 B
import * as Cookies from 'js-cookie'; export declare type IUseCookieValueOptions<InitializeWithValue extends boolean | undefined = boolean | undefined> = Cookies.CookieAttributes & (InitializeWithValue extends undefined ? { /** * Whether to initialize state with cookie value or initialize with `undefined` state. * * Default to false during SSR * * @default true */ initializeWithValue?: InitializeWithValue; } : { initializeWithValue: InitializeWithValue; }); export declare type IUseCookieValueReturn<V extends undefined | null | string = undefined | null | string> = [ value: V, set: (value: string) => void, remove: () => void, fetch: () => void ]; export declare function useCookieValue(key: string, options: IUseCookieValueOptions<false>): IUseCookieValueReturn; export declare function useCookieValue(key: string, options?: IUseCookieValueOptions): IUseCookieValueReturn<null | string>;