reactjs - Webkit-flex 未在 next.js 中的反应子组件上呈现
问题描述
下面是两种不同的方法,它们在从 styled-components 渲染 next.js 时给出不同的 css 结果:
index.js:
return (
// list the children
{data.map((item, key) => (
<ParentComp key={key || "0"}>
<ChildComp data={item} />
</ParentComp>
//...
相比:
return (
// state each children
<ParentComp>
<ChildComp/>
<ChildComp/>
</ParentComp>
//...
将呈现我在开发者控制台上看到的不同 css:
/* when the children is listed */
.ParentComp {
display: flex;
flex-direction: row;
flex-wrap: wrap;
-webkit-box-pack: center;
justify-content: center;
align-items: flex-start;
}
.ChildComp {
min-height: 400px;
width: 264px;
flex: 0 0 264px;
margin: 5px;
}
相比:
/* when each children is stated (the intended one) */
.ParentComp {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-items: flex-start;
-webkit-box-align: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
.ChildComp {
-webkit-flex: 0 0 264px;
-ms-flex: 0 0 264px;
flex: 0 0 264px;
margin: 5px;
min-height: 400px;
width: 264px;
}
即使它们来自相同styled-component
的组件(ParentComp
和ChildComp
),包含相同的代码,因此在浏览器上预期的行为相同(它们不是)。
当然,我可以将预期的 css 结果完全覆盖到styled-component
's 组件并解决了问题,但尽管如此,这件事让我感到困惑,应该归咎于哪一部分(next.js/styled-component/甚至是我使用的 bulma-styled-components ) 并且该解决方案不实用(复制完整的 css 渲染结果)。
有人对此有所了解吗?谢谢。
更新:
即使复制到样式组件的组件后问题仍然没有解决,我将尝试对此进行最小化回购。
更新二:
这是最小的回购:
https://codesandbox.io/s/wqoxjq31wl
您可以尝试在编辑器处更改eachComp
为以了解我的意思。listComp
index.js
解决方案
我的错...
它应该是这样的:
<ParentComp >
{data.map((item, key) => (
<ChildComp key={key || "0"} data={item} />
))}
</ParentComp >
推荐阅读
- html - 为什么我不能在表格上输入文字?
- discord.py - 解禁ID | 我使用了解禁命令,但仍然无法使用 ID 解禁
- javascript - fullcalendar.io 5:addEventSource 不能从外部函数工作
- javascript - 使用 ScrollTop 的聊天框不适用于使用 jQuery 的下一个包装类
- r - 使用 ddply 找不到对象
- twilio-twiml - 是否可以在调用客户端而不是数字时控制 callerid 输出?
- colors - 如何更改 HTML 文档中的背景颜色?
- facebook - Facebook 页面未显示在移动应用程序中。怎么修?
- google-cloud-firestore - 在 Firestore 服务器库上写入后读取
- python - Pytorch 张量表示具有颜色值的 3D 网格