Cookie
cookieBackend
is the wrapper of js-cookie (opens in a new tab)
Hooks
const ComponentWithCookieBackend = () => {
const { cookieBackend } = useGlobal();
// ... your code
};
Saga
import { getContext } from 'redux-saga/effects';
export function* functionWithCookieBackend() {
const { cookieBackend } = yield getContext('useGlobal');
// ... your code
}
Apis
# Get a cookie value
cookieBackend.get("name");
// Set a string to name
cookieBackend.set("name", "string value");
// return number or undefined
cookieBackend.getInt("name");
Best practices
Cookie will send data it contains back to server in every request, so do not store more data than you need in cookie.