【发布时间】:2020-04-20 03:01:10
【问题描述】:
我正在尝试理解布局中名为 AppMounted 的组件的逻辑 (Gatsby 1)
import { Component } from 'react';
export default class AppMounted extends Component {
componentDidMount() {
/* eslint-disable no-undef */
// If the body element does not yet contain the "app-mounted" class
if (!document.body.classList.contains('app-mounted')) {
// Wait just a little longer
setTimeout(() => {
// And then add it
document.body.classList.add('app-mounted');
}, 50);
}
/* eslint-enable no-undef */
// 50
}
render() {
return null;
}
}
然后是正文的scss样式
body {
visibility: hidden;
&.app-mounted {
visibility: visible;
}
}
据我了解,这将等待所有 50 毫秒以加载组件/数据然后显示它们。但如果没有这个组件,一切也都可以完美运行。问题是它在 Gastby 2 上造成了麻烦并隐藏了一切。通过在 Gastby 2 版本中取出它,一切都恢复正常了。有什么理由需要隐藏身体然后再次显示它?
任何反馈都将不胜感激,谢谢!
【问题讨论】:
标签: javascript css reactjs sass gatsby