Questions tagged [react-cookie]
46 questions
45
votes
5 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: {…
![](../../users/profiles/7715114.webp)
Ugo Nicolai
- 529
- 1
- 6
- 11
6
votes
4 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',…
![](../../users/profiles/6003249.webp)
JasonA
- 181
- 1
- 2
- 12
4
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…
![](../../users/profiles/79891.webp)
meds
- 17,850
- 30
- 131
- 265
3
votes
3 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.…
![](../../users/profiles/6049829.webp)
Peter rosevelt
- 536
- 1
- 8
- 25
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…
![](../../users/profiles/8169825.webp)
Prasaad Patil
- 357
- 1
- 5
- 17
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 {
…
![](../../users/profiles/9536421.webp)
Amber Normand
- 363
- 1
- 4
- 8
1
vote
1 answer
Warning: Text content did not match. Server: "I'm out" Client: "I'm in" div NEXTJS
(I have already looked everywhere for a solution)
Im using universal-cookie in nextjs project and this the simple code that return a Warning in console:
import React, { useState } from "react";
import Cookies from "universal-cookie";
import styles…
![](../../users/profiles/13625491.webp)
andres martinez
- 79
- 10
1
vote
1 answer
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…
![](../../users/profiles/12196277.webp)
wischn
- 13
- 4
1
vote
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":…
![](../../users/profiles/7486447.webp)
ARKhan
- 736
- 11
- 17
1
vote
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.…
![](../../users/profiles/10729355.webp)
Otavio Bonder
- 1,015
- 1
- 7
- 19
1
vote
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',…
![](../../users/profiles/538471.webp)
dan-klasson
- 12,215
- 11
- 49
- 91
1
vote
1 answer
Invalid prop `cookies` when running test with react cookies
I'm using react-cookies package in my app and trying to write tests into my app. I'm trying to mock cookie.remove method and validate it, below are the codes:
// App.js
export class App extends Component {
static propTypes = {
cookies:…
![](../../users/profiles/9206753.webp)
Jee Mok
- 4,537
- 7
- 35
- 66
1
vote
0 answers
Not able to remove cookies with react-cookie
I'm using react-cookie for setting cookies in the browser. Now I want to remove a cookie. Unfortunately I'm not able to remove the string using the following call:
cookies.remove(cookies.cookies.slug,{ path: '/'})
If I console.log the remove call I…
![](../../users/profiles/1659913.webp)
WDP
- 183
- 3
- 13
1
vote
1 answer
React-cookie giving "Check the render method of `CookiesProvider`" error
I'm trying to use cookies in my react app but cannot make react-cookie module to work. I'm using example from this page: https://www.npmjs.com/package/react-cookie
but it gives me the following error:
Element type is invalid: expected a string (for…
![](../../users/profiles/2498528.webp)
AnKing
- 1,257
- 20
- 33
1
vote
1 answer
create separate react component for cookie management
I have a component which renders if its prop.paramA is different from paramA value stored in cookie.
Following is my attempt to move the cookie management logic into a separate component. The problem is that the question component gets rendered…
![](../../users/profiles/1323517.webp)
comiventor
- 3,034
- 4
- 35
- 64