A hook for managing cookies with get, set, and delete functionality.
name
(string
): The name of the cookie.defaultValue
(string
): The initial value of the cookie.
- An array containing:
- The current cookie value.
- Functions to set and delete the cookie.
- Cookies from
js-cookie
import useCookie from "./useCookie"
export default function CookieComponent() {
const [value, update, remove] = useCookie("name", "John")
return (
<>
<div>{value}</div>
<button onClick={() => update("Sally")}>Change Name To Sally</button>
<button onClick={remove}>Delete Name</button>
</>
)
}