material-ui - 使用 Material-UI 和 NextJS 的类名不匹配
问题描述
使用 Intersection Observer API,我试图通过视口上的可见性来呈现 Material-UI 组件。
export default function Index() {
const [onScreen, theRef] = useOnScreen({
rootMargin: "-300px",
ssr: true
});
const classes = useStyles();
return (
<Container maxWidth="sm">
<DummyContainer />
<div
ref={theRef}
style={{
height: "100vh",
padding: "20px",
backgroundColor: "green",
transition: "all .5s ease-in"
}}
>
{onScreen && (
<Box className={classes.rootBox} my={16}>
<Typography variant="h2" gutterBottom>
Content Lazy using Intersection Observer
</Typography>
<Copyright />
</Box>
)}
</div>
<Box className={classes.rootBox} my={4}>
<Typography variant="h2" gutterBottom>
Content no lazy, why this Box loses margin?
</Typography>
<Typography gutterBottom>
If you request this page with JavaScript disabled, you will notice
that has been properly rendered in SSR
</Typography>
</Box>
</Container>
);
}
基本的东西,onScreen 是一个使用 Intersection Observer 的切换布尔值
为了“对 SEO 友好”,我正在使用 NextJS,并且我希望这个组件在 SSR 中始终可见,并且在 CSR 中有条件地可见。
问题出现在 CSR 的补液过程中,似乎重新创建了惰性组件之后的一些类名,并且我在第二个 Box 组件中失去了样式。
我创建了这个 CodeSandbox 来看看:https ://codesandbox.io/s/nextjsmaterialuiclassnamemismatch-1j4oi
这是 MaterialUI、JSS 中的错误吗?或者很可能我做错了什么?
解决方案
推荐阅读
- javascript - 我想对路由器做出反应以呈现新页面
- r - 如何按月顺序对列进行排序并计算列 R data.table 之间的差异
- docker - 如何从绑定到 localhost 的 docker 容器访问主机端口
- javascript - 'ref' 未定义 no-undef 我想尝试从 Firebase 存储加载图像
- maven - Maven构建期间自动下载Edge Webdriver时出错
- javascript - 在反应中 - 覆盖输入元素的 stepUp 和 stepDown
- angular - 使用 ngx-translate 在角度 Web 组件中进行空翻译
- javascript - 如何在画布上画画?
- html - Safari中颤抖的css运行文本动画(边距+翻译)
- c++ - 模板类内模板类推导模板参数