import Cookies from "js-cookie" import { useCallback, useState } from "react" /** * Copied from react-use * https://github.com/streamich/react-use/blob/e1d0cd9f7fb2a124a9d46879489abfefdf48d836/src/useCookie.ts#L4 */ export const useCookie = ( cookieName: string, ): [ string | null, (newValue: string, options?: Cookies.CookieAttributes) => void, () => void, ] => { const [value, setValue] = useState( () => Cookies.get(cookieName) || null, ) const updateCookie = useCallback( (newValue: string, options?: Cookies.CookieAttributes) => { Cookies.set(cookieName, newValue, options) setValue(newValue) }, [cookieName], ) const deleteCookie = useCallback(() => { Cookies.remove(cookieName) setValue(null) }, [cookieName]) return [value, updateCookie, deleteCookie] }