0

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.

Here is my code

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;

I had read their own documentation and tried research and read many articles but nothing help so far.

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
user12660992
  • 59
  • 1
  • 3
  • 12

1 Answers1

1

I do not know for certain what two objects are being created in your case. However, it looks like the following could be what you are seeing:

https://github.com/Mastermindzh/react-cookie-consent#why-are-there-two-cookies-one-of-which-named-legacy

The documentation describes storing two cookies to ensure maximum browser compatibility.

mark
  • 35
  • 5