Skip to main content

useCookie

Callable

  • useCookie<CookieValues>(options?: any): readonly [cookies: CookieValues, methods: { getCookie: <Name>(name: Name) => CookieValues[Name] | null; removeCookie: <Name>(name: Name, attributes?: CookieDomainAttributes) => void; setCookie: <Name>(name: Name, value: CookieValues[Name]) => void }]

  • React hook for managing cookies.

    @example
    function App() {
    const [cookies, { setCookie, removeCookie }] = useCookie({
    initialValue: {
    theme: 'dark'
    }
    })

    return <h1>Theme: {cookies.theme}</h1>
    }

    Type parameters

    • CookieValues: Record<string, any>

    Parameters

    • optionaloptions: any

      Cookie options.

    Returns readonly [cookies: CookieValues, methods: { getCookie: <Name>(name: Name) => CookieValues[Name] | null; removeCookie: <Name>(name: Name, attributes?: CookieDomainAttributes) => void; setCookie: <Name>(name: Name, value: CookieValues[Name]) => void }]