main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
609 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import { useCallback, useState } from 'react';
|
---|
| 2 | import Cookies from 'js-cookie';
|
---|
| 3 | var useCookie = function (cookieName) {
|
---|
| 4 | var _a = useState(function () { return Cookies.get(cookieName) || null; }), value = _a[0], setValue = _a[1];
|
---|
| 5 | var updateCookie = useCallback(function (newValue, options) {
|
---|
| 6 | Cookies.set(cookieName, newValue, options);
|
---|
| 7 | setValue(newValue);
|
---|
| 8 | }, [cookieName]);
|
---|
| 9 | var deleteCookie = useCallback(function () {
|
---|
| 10 | Cookies.remove(cookieName);
|
---|
| 11 | setValue(null);
|
---|
| 12 | }, [cookieName]);
|
---|
| 13 | return [value, updateCookie, deleteCookie];
|
---|
| 14 | };
|
---|
| 15 | export default useCookie;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.