@supunlakmal/hooks
Version:
A collection of reusable React hooks
25 lines (24 loc) • 1.17 kB
TypeScript
/**
* @name useCookie
* @description - Hook that manages a specific browser cookie.
*
* @param {string} cookieName The name of the cookie to manage.
* @param {string} [initialValue] The initial value to use if the cookie is not set.
* @returns {[string | null, (value: string, options?: { expires?: Date | number; path?: string; domain?: string; secure?: boolean; sameSite?: 'Strict' | 'Lax' | 'None' }) => void, (options?: { path?: string; domain?: string }) => void]} A tuple containing the cookie's current value (or initialValue/null), a function to update the cookie, and a function to delete the cookie.
*
* @example
* const [username, setUsername, deleteUsername] = useCookie('username', 'Guest');
*
* setUsername('ReactUser', { expires: 7 }); // Set cookie for 7 seconds
* deleteUsername(); // Delete the cookie
*/
export declare const useCookie: (cookieName: string, initialValue?: string) => [string | null, (value: string, options?: {
expires?: Date | number;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: "Strict" | "Lax" | "None";
}) => void, (options?: {
path?: string;
domain?: string;
}) => void];