【发布时间】:2021-10-18 03:03:11
【问题描述】:
我想在每个用户会话中显示一个弹出模式,我想知道如何在我的 React 应用程序中合并 jquery cookie,以便网站知道用户何时返回并且在用户的 cookie 数据之前不会再次显示模式已被清除。这是我的代码:
import React from "react";
import styled from "styled-components";
const Modal = ({ showModal, setShowModal }) => {
return (
<>
{showModal ? (
<Wrap>
<TopWrap>
<h1>IMPORTANT</h1>
<Close onClick={() => setShowModal(false)}>Close</Close>
</TopWrap>
<h3 style={{ fontWeight: "200" }}>
text here
</h3>
</Wrap>
) : null}
</>
);
};
const Wrap = styled.div`
position: fixed;
background: white;
width: 350px;
padding: 20px;
bottom: 2%;
right: 2%;
z-index: 1000;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
border-radius: 20px;
`;
const TopWrap = styled.div`
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
`;
const Close = styled.h4`
color: #aaa;
cursor: pointer;
margin-bottom: 20px;
&:hover {
color: black;
}
`;
export default Modal;
我正在使用 React 钩子,因此当用户按下“关闭”文本时,它会关闭模式。我要解决的问题是每次刷新页面时都会出现模式,并且我希望每个会话只显示一次。我知道可以使用 JQuery 在 HTML 中执行此操作,但我不确定如何在 React 中实现。
【问题讨论】:
标签: javascript html jquery reactjs react-hooks