reactjs - react-cookie-consent 在点击时存储数据两次
问题描述
嘿,我现在正在使用这个 npm 包https://www.npmjs.com/package/react-cookie-consent在我的反应类型脚本应用程序中创建 cookie 同意,通过这个包,我可以在用户许可后将一些数据存储在 cookie 中. 现在有两个问题,首先它在单击接受按钮后存储,它将两个对象存储在 cookie 中,其次,cookie 的更改没有立即显示在 cookie 部分的应用程序选项卡中,我必须重新加载才能看到更改。
这是我的代码
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;
我已经阅读了他们自己的文档并尝试研究并阅读了许多文章,但到目前为止没有任何帮助。
解决方案
我不确定在您的情况下创建了哪两个对象。但是,您可能会看到以下内容:
该文档描述了存储两个 cookie 以确保最大的浏览器兼容性。
推荐阅读
- api - 在 Playstore 中重新发布应用后 API 无法工作
- python - 如何在 Scrapy 爬虫中进行代理?
- python - Odoo14基于用户组隐藏菜单系统托盘?
- anylogic - 如何根据交货地点和库存水平批量代理
- amazon-ec2 - 如何在 Lambda 中从警报中提取特定信息(如实例 ID)(使用成本指标)
- vb.net - VB.NET Docker 失败
- sql - 撤消 COPY 命令 redshift | 从红移中删除
- c++ - 如何组合具有相同代码的两个模板函数?
- docker - 将 GCP 永久磁盘挂载为 NFS
- mysql - 如何使用 wamp 在本地访问我的 react js 应用程序并允许访问其他计算机?