UNPKG

@sophat/cookies

Version:

This project provides a set of utility functions for interacting with browser cookies. The `Cookies` class offers methods to set, get, update, remove, and clear cookies, as well as retrieve all cookie keys.

33 lines (32 loc) 1.04 kB
import { CookieOptions } from '../interfaces/cookie-options'; /** * Custom hook for managing cookies in a React application. * @returns An object containing methods to manipulate cookies: * - `setCookie`: Sets a cookie with the specified name, value, and options * - `getCookie`: Retrieves a cookie value by name * - `removeCookie`: Removes a cookie by name * - `getKeys`: Gets an array of all cookie names * * @example * ```typescript * const { setCookie, getCookie, removeCookie, getKeys } = useCookie(); * * // Set a cookie * setCookie('user', 'john', { expires: 7 }); * * // Get a cookie * const value = getCookie('user'); * * // Remove a cookie * removeCookie('user'); * * // Get all cookie names * const cookieNames = getKeys(); * ``` */ export declare const useCookie: () => { getCookie: (name: string) => string | null; setCookie: (name: string, value: string, options?: CookieOptions) => void; removeCookie: (name: string, options?: CookieOptions) => void; getKeys: () => string[]; };