0
我正在与reactjs一起使用firebase,我有一个渲染从firebase获取的数据的问题。如何强制Firebase数据库调用同步?
我的reactjs组件在数据之前加载,所以当我的网页加载时,它在数据显示之前很短时间内保持空白。
但我不希望我的页面加载没有数据已成功加载之前。所以,我试图在构造函数中操纵状态,但我认为问题来自Firebase。由于火力甚至在constructor()
和componentDidMount()
所以render()
即使火力点没有完成发送数据被称为异步获取数据。
如何完全防止反应呈现没有firebase没有发送结果?
constructor(props){
super(props)
post = database.ref().child('posts').orderByKey().equalTo(id)
post.once('value').then(snap => {
// I get the snap here but i don't want my page to render before
// all data queried have been fetched
}).then(function(){
// I've tried to add a "then" callback but it doesn't work
// Render is still displayed too soon
})
}
render(){
let data = this.state.data
return(
// simple example
<span>{this.state.data}</span>
)
}
感谢。
谢谢它最后的工作。你解决了我的问题。我加载了ReactDomRender的所有内容,现在全部都完美了。 – John