use-cookie-popup
Version:
React hook to work with cookie popup
37 lines (34 loc) • 1.34 kB
TypeScript
import * as react from 'react';
import { SerializeOptions } from 'cookie';
interface UseCookieProps {
name: string;
showUpDelay?: number;
optsCookieDecline?: SerializeOptions;
optsCookieAccept?: SerializeOptions;
showAlways?: boolean;
showIfAccepted?: boolean;
showIfDeclined?: boolean;
}
/**
* React hook for working with cookie popup
*
* Cookie value is 'true' if cookie was accepted, and 'false' if cookie was rejected
*
* @param name - name of a cookie,
* @param showUpDelay - cookie apperas after this delay
* @param optsCookieAccept - opts for setting cookie when accept
* @param optsCookieDecline - opts for setting cookie when decline
* @param showAlways - isVisible will be true before accepting/declining
* @param showIfAccepted - isVisible will be true before accepting
* @param showIfDeclined - isVisible will be true before declining
* @returns isVisible for popup and tools for managing visibity
*/
declare const useCookiePopup: ({ name, showUpDelay, optsCookieAccept, optsCookieDecline, showAlways, showIfAccepted, showIfDeclined, }: UseCookieProps) => {
isVisible: boolean;
setIsVisible: react.Dispatch<react.SetStateAction<boolean>>;
onAccept: () => void;
onDecline: () => void;
onClose: () => void;
};
export { useCookiePopup };
export type { UseCookieProps };