Questions tagged [react-cookie]
72 questions
84
votes
8 answers
Get cookie with react
I need to know if my user is connected or not. For that I want to read the cookies that I set in the server side with express-session :
app.use(session({
secret: 'crypted key',
resave: false,
saveUninitialized: true,
cookie: {…

Jackal
- 1,041
- 1
- 10
- 13
7
votes
5 answers
react-cookie unable to set expires or maxAge
I cannot seem to set the expiration for a cookie with react-cookie... here is my setup:
import { Cookies } from 'react-cookie'
const cookies = new Cookies()
import moment from 'moment'
The following attempts have failed:
cookies.set('cookieName',…

JasonA
- 241
- 2
- 5
- 13
7
votes
1 answer
Cookies are deleted when I close the browser?
I've been using window.localstorage to save some data without problem, the data was persisting between sessions.
I decided to switch to using cookies, using 'react-cookie', code as follows:
import Cookies from 'react-cookie';
export default class…

meds
- 21,699
- 37
- 163
- 314
4
votes
0 answers
React-cookie not updating when changed from console
I'm working with the react-cookie library and am running into an issue. Basically, when a cookie is changed from the console, the app doesn't refresh the cookie and keeps the old saved one. For example, if the value of the original cookie was 123…

sofshant
- 183
- 1
- 9
4
votes
4 answers
React: Delete cookie when user closes the browser
I'm using the library react-cookie (https://www.npmjs.com/package/react-cookie) and I want to delete the user cookies when the browser or tab is closed. I used ComponentWillUnmount in my Approuter, but that doesn't work when the browser is closed.…

djamaile
- 695
- 3
- 12
- 30
3
votes
2 answers
Trigger when a cookie changes on client's browser? - React JS
im going to add a new feature to the existing php site using react js. i want to do something when a specific cookie changed on clients browser side. this cookie is used to authenticate the user in react.
i used both 'react-cookie','js-cookie'…

Tiran
- 31
- 1
- 4
3
votes
3 answers
Mocking a cookie in react-cookie
I'm trying to set a cookie in my test to make sure it's getting cleared out in my component:
import Cookies from 'universal-cookie';
test('successfully logs the user out', async () => {
const cookie = new Cookies()
cookie.set('authtoken',…

dan-klasson
- 13,734
- 14
- 63
- 101
3
votes
1 answer
How to import react-cookie in typescript
I am creating an app in react using the react template provided by visual studio 2017. I want to make use of react-cookie in my application. I have installed this lib using command
npm install react-cookie
But when i try to import it in my…

Prasaad Patil
- 447
- 3
- 6
- 20
3
votes
1 answer
How do I get cookies in react js using react-cookie?
The react-cookie docs have this example
import React, { Component } from 'react';
import { instanceOf } from 'prop-types';
import { withCookies, Cookies } from 'react-cookie';
import NameForm from './NameForm';
class App extends Component {
…

Amber Normand
- 650
- 1
- 6
- 10
2
votes
1 answer
Type error: Property 'get' does not exist on type 'typeof import("js-cookie")'
I'm unable to build the following JS react code:
import Cookies from 'js-cookie';
React.useEffect(() => {
interface UserInfo {
name: string;
verified: boolean;
}
const userInfo = Cookies.get('userInfo');
if (userInfo &&…

user8411456
- 347
- 1
- 5
- 18
2
votes
0 answers
How to detect if a cookie has been deleted
I have a ReactJS 17.0.2 application that made use of a couple of cookies to check if a user is logged in.
I use import { useCookies } from 'react-cookie';
If the user is logged in, he/she can open another tab in the browser, and being automatically…

Paolo Di Pietro
- 517
- 3
- 17
2
votes
2 answers
Gatsbyjs google analytics gdpr
I want to use google analytics in my website, but be gdpr compliant, so only fire it, when the user consents.
I am using gatsby and followed this tutorial: https://www.improvebadcode.com/gatsby-gdpr-cookie-consent/, which makes total sense in my…

wischn
- 21
- 6
2
votes
1 answer
Getting cookie.load('csrftoken') undefined in react
I am sending axios.put request on my Django back-end (DRF). I am using react. GET request seems to work nicely. This is my code:
const options = {headers:
{"X-CSRFToken":…

ARKhan
- 1,724
- 22
- 30
2
votes
1 answer
How to invoke a fresh update of cookies on React App?
I have a React app. I have the following react hook to get cookies using react-cookie.
const [cookies] = useCookies(["basket"]);
I already successfully get the cookie basket. Is there anyway for me to invoke a fresh update on the cookie "basket" if…

kyle
- 21
- 2
2
votes
0 answers
React: setCookie hook doesn't set any cookie
I'm trying to integrate Auth0 to my SPA. I'm embedding the Lock feature, so it handles authentication by itself.
I can login, and the Lock feature works fine, however I'm trying to save the accessToken and the idToken returned by Lock to a cookie.…

Otavio Bonder
- 1,789
- 4
- 17
- 35