javascript - 为什么工具提示被渲染两次?
问题描述
出于某种原因,react-tooltip 正在渲染 2 个工具提示,当我只要求它渲染一个(当然)时,这是我的一个 react 组件的示例:
但是,它不应该,因为代码只呈现一次。让我给你看一下反应代码:
import React from "react";
import ReactTooltip from "react-tooltip";
import "./StaffMembers.scss";
import ProfileIcon from "../public/profile.svg";
function getKeysAndValues<T>(item: T[]) {
return Array.from(item.entries());
}
export interface StaffDetails {
pfp: string;
email: string;
}
const StaffMembers: React.FC<{ staff: StaffDetails[] }> = (props) => {
return (
<>
<div className="staffMembers">
<h1 className="title">All Staff Members</h1>
<div className="staffTable">
{getKeysAndValues(props.staff).map(([id, staff]) => (
<div className="staffMember" key={id}>
<div className="userDetail">
<img
className="pfp"
src={staff.pfp}
alt="pfp"
/>
<p className="email" data-tip={staff.email}>
{staff.email}
</p>
</div>
<button className="copyBtn">Copy UID</button>
<button className="logoutBtn">Log-out</button>
</div>
))}
</div>
</div>
<ReactTooltip />
</>
);
};
export default StaffMembers;
以及该组件的 SCSS:
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;400;500&display=swap');
.staffMembers::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
background-color: #F5F5F5;
}
.staffMembers::-webkit-scrollbar {
width: 12px;
background-color: #F5F5F5;
}
.staffMembers::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .3);
background-color: #555;
}
.staffMembers {
background: #FEFEFF;
border: 3px solid rgba(217, 217, 217, 0.5);
box-sizing: border-box;
border-radius: 10px;
width: 450px;
display: flex;
flex-direction: column;
align-items: center;
.title {
font-family: Poppins;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 36px;
text-align: center;
padding: 20px;
color: #000000;
}
.staffTable {
width: 100%;
border-top: 1px solid rgba(217, 217, 217, 0.5);
border-collapse: collapse;
display: flex;
flex-direction: column;
max-height: 350px;
display: block;
overflow-y: auto;
white-space: nowrap;
}
.staffMember {
border-bottom: 1px solid rgba(217, 217, 217, 0.5);
display: flex;
align-items: center;
justify-content: space-around;
}
.userDetail {
font-family: Poppins;
font-style: normal;
font-weight: normal;
font-size: 14px;
display: flex;
align-items: center;
flex-direction: row;
}
.pfp {
height: 41px;
}
.email {
margin-left: 15px;
width: 150px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.copyBtn {
border: 0;
background: #7EDD7E;
border-radius: 5px;
font-family: Poppins;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 18px;
/* identical to box height */
text-align: center;
color: #000000;
height: 25px;
}
.logoutBtn {
border: 0;
background: #FA2C2C;
border-radius: 5px;
font-family: Poppins;
font-style: normal;
font-weight: normal;
font-size: 12px;
line-height: 18px;
/* identical to box height */
text-align: center;
color: #000000;
height: 25px;
}
}
我无法弄清楚到底出了什么问题——因为我只在<p>
标签上调用了一次 data-tip 道具。
谢谢您的帮助。
解决方案
推荐阅读
- soap - 在 SoapUI 中将文件附件作为 base64Binary 发送
- string - 为什么我收到错误消息“无效号码”,因为 UserID 是 NUMBER
- node.js - 看不到后端发送的 react js 中的 cookie
- python - 将数据从 python 脚本写入 influxdb 的问题
- powershell - 如何在 Powershell 中查看所有 XML 级别
- python - plotly中的水平表和图表
- javascript - 我可以在 package.json 中包含 bash/sh 文件作为依赖项吗?
- angular - 我可以将管道添加到绑定@input decoprador 属性吗?
- javascript - 从页面源中隐藏 HTML 表单操作 url
- matlab - 如何在 MATLAB 中随时间在 x 轴上对矩形进行着色?