reactjs - 在渲染之前插入dom元素?
问题描述
我正在使用谷歌地图来显示一个地方。但我在 componentdidmount 阶段更新了地图地址。而且我正在使用另一个函数来创建 dom 元素。所以当我第一次进入地图页面时,我得到错误。因为将插入地图的 dom 元素将在渲染后位于 DOM 内。所以没有刷新我无法对地图页面做出反应。刷新后我可以。知道吗?(我正在使用 MERN)
componentDidMount() {
const {
match: {
params: { id }
}
} = this.props;
this.props.getListById(id)
.then(list => {
return getLocationAddressAndPlace(
document.getElementById('__maps'), // This _maps div is not created, will be created after the render.
list.address.locationName
)
})
.catch(err => {
toast.error(err);
});
}
解决方案
推荐阅读
- react-native - React Native - 重定向到“主页”后显示启动画面
- android - Android VpnService 不允许自己
- r - 如何从原始数据集中计算样本数据集?
- python - 以节省内存的方式将加权边列表转换为邻接矩阵
- travis-ci - 电子邮件验证错误和未触发自动构建
- c# - Json 使用动态属性名称反序列化对象数组
- c++ - 找到您正在考虑的数字的程序无法正常运行,出了什么问题?
- javascript - V8 c++ - 无法反序列化 V8 快照 blob
- javascript - 如何使用jquery预填充字段
- django - 使用 Django 上传一个大的 csv 文件(100MB)需要多长时间?