useCookie
The useCookie hook provides a reactive interface for managing browser cookies. More Info...
import { useCookie } from '@archibald/server';
const [value, set, clear] = useCookie(NAME, OPTIONS);
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| name | string | ✔️ | The name of the cookie. |
| options | CookieOptions | Configuration for the hook. |
CookieOptions
| Property | Type | Default | Description |
|---|---|---|---|
| updateOnRefocus | boolean | true | If true, the hook re-reads the cookie value when the window gains focus. |
Return Value
- Type:
readonly [string, (value: string, options?: CookieSetOptions) => void, (options?: CookieSetOptions) => void]
The hook returns a tuple containing:
- The current cookie value.
- A setter function to update the cookie.
- A clear function to remove the cookie.