javascript - Map 函数在使用 tailwind 的实用程序类时以不同方式呈现第一个反应元素
问题描述
我在我的项目中使用 Tailwind for CSS,并映射到这样的 React 按钮元素:
<div className="flex flex-wrap justify-center items-center space-x-1 space-y-1">
{domains.map((domain, index) => {
return (
<Button
key={index}
bgColor="transparent"
hoverEffect="blue-500"
textColor="gray-700"
textHover="white"
boarder="blue-500"
boarderHover="blue-500"
otherClasses="text-xs block rounded-full px-4"
selcted="blue-500"
buttonTitle={domain}
/>
);
})}
</div>
编辑1:这是按钮组件
export const Button = ({
bgColor,
hoverEffect,
textColor,
textHover,
boarder,
boarderHover,
otherClasses,
buttonTitle,
selcted,
}) => {
return (
<>
<div className="block">
<button
className={
`bg-${bgColor} ${hoverEffect && `hover:bg-${hoverEffect}`}
text-${textColor} ${textHover && `hover:text-${textHover}`}
border border-${boarder} hover:border-${boarderHover} ${otherClasses}` +
` lg:focus:bg-${selcted ?? selcted} lg:focus:text-${textHover}`
}
>
{buttonTitle}
</button>
</div>
</>
);
};
如果我渲染此代码,它会返回如下内容:(https://drive.google.com/file/d/1XqxRQ6bUTSQqZTJVqbv-c9Rs4hXy01J2/view?usp=sharing)
当我使用 flex 或 grid 时,地图中的第一个项目会获得不同的方向。我不明白我在这里做错了什么。如果我手动渲染几次,它会正确渲染。
解决方案
伙计们抱歉更新晚了。但我发现这是tailwind CSS中垂直空间选项的一些问题。
class= "space-y-6"
类似的东西。如果您正在使用它,请尝试删除它。或找到解决方法,它应该可以工作。
推荐阅读
- c# - Azure - 推送通知 - 无法发送测试消息
- elasticsearch - 最小化垃圾收集
- javascript - JavaScript 如何防止在 Promise 中推送 null?
- unix - 将文本粘贴到unix中的文件名
- php - 在php中为新日期重置计数器
- angular - 无法将 ngx-bootstrap-modal 与 Angular Universal 一起使用
- reactjs - 在无限循环中响应 Downshift 自动完成请求
- php - 从数据库中检索包含 Laravel 中相同值的行
- c# - 创建应用程序以使用 C# 配置 Timer
- html - IE 11 中的 Flexbox 重叠