Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-cookie-consent storing data twice on click #77

Closed
iamAbdulAhad3481 opened this issue Jul 6, 2020 · 6 comments
Closed

react-cookie-consent storing data twice on click #77

iamAbdulAhad3481 opened this issue Jul 6, 2020 · 6 comments

Comments

@iamAbdulAhad3481
Copy link

Hey i am using this npm package https://www.npmjs.com/package/react-cookie-consent for creating a cookies consent in my react type script app now and through this package i can store some data in cookies after user permission. Now there are two problems first it is storing after clicking on accept button it stores two object in cookies, second the change in cookies is not showing immediately in application tab in cookies section i had to reload to see the changes.


import React, {FC} from 'react'
import CookieConsent from "react-cookie-consent";

const CookiesBar : FC<any> = ({closeCookieBar}) => {
  const lang = localStorage.getItem('language');
  return (
    <CookieConsent
      location="bottom"
      enableDeclineButton
      buttonText="I understand"
      declineButtonText="Decline"
      style={{ background: "#2B373B" }}
      cookieName="language"
      cookieValue={`${lang}`}
      buttonStyle={{ color: "#4e503b", fontSize: "13px" }}
      declineButtonStyle={{ fontSize: "13px" }}
      setDeclineCookie={false}
      onAccept={({ acceptedByScrolling }) => {
        if (!acceptedByScrolling) {
          closeCookieBar();
        }
      }}
      onDecline={() => closeCookieBar()}
    >
      This website uses cookies to enhance the user experience.{" "}
    </CookieConsent>
  )
}
export default CookiesBar;

@iamAbdulAhad3481
Copy link
Author

iamAbdulAhad3481 commented Jul 6, 2020

@Mastermindzh can you please help me out. It might be possible i am doing something wrong.

@Mastermindzh
Copy link
Owner

The reload on the cookie tab is normal. That is a browser thing. The cookie is available instantly but the UI just doesn't refresh on its own.

It setting two cookies is also perfectly normal. One of them is named "legacy" because some browsers can't read the first cookie because of the same-site settings. See issue for more details. I will add an explanation to the readme so others are aware as well.

@iamAbdulAhad3481
Copy link
Author

It save two cookies of same name in my case 'language'

@Mastermindzh
Copy link
Owner

Mastermindzh commented Jul 7, 2020

Can you provide a stackblitz or some more code?

@iamAbdulAhad3481
Copy link
Author

Can you provide a stackblitz or some more code?

It worked thanks now 2 cookies are storing 1 is which. i am storing an other with legacy. Any ways thanks for replies @Mastermindzh

@Mastermindzh
Copy link
Owner

No problem, glad it's resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants