|
Download react-use/docs/useCookie.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useCookie.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useCookie.md
-
curl -L -o useCookie.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useCookie.md
825 Bytes
| # `useCookie` | |
| React hook that returns the current value of a `cookie`, a callback to update the `cookie` | |
| and a callback to delete the `cookie.` | |
| ## Usage | |
| ```jsx | |
| import { useCookie } from "react-use"; | |
| const Demo = () => { | |
| const [value, updateCookie, deleteCookie] = useCookie("my-cookie"); | |
| const [counter, setCounter] = useState(1); | |
| useEffect(() => { | |
| deleteCookie(); | |
| }, []); | |
| const updateCookieHandler = () => { | |
| updateCookie(`my-awesome-cookie-${counter}`); | |
| setCounter(c => c + 1); | |
| }; | |
| return ( | |
| <div> | |
| <p>Value: {value}</p> | |
| <button onClick={updateCookieHandler}>Update Cookie</button> | |
| <br /> | |
| <button onClick={deleteCookie}>Delete Cookie</button> | |
| </div> | |
| ); | |
| }; | |
| ``` | |
| ## Reference | |
| ```ts | |
| const [value, updateCookie, deleteCookie] = useCookie(cookieName: string); | |
| ``` | |