0
我在firebase中有一些記錄,這段代碼是將其取出並將結果放到子組件中。這裏的代碼ReactJS - 如何獲得Firebase結果並正確傳遞到子組件
import React from "react";
export default class Home extends React.Component{
componentWillMount(){
this.firebaseRef = new Firebase('https://sweltering-heat-7923.firebaseio.com/contact');
this.firebaseRef.once("value", function (snapshot){
snapshot.forEach(function(data){
console.log(data.val());
});
});
}
render(){
return(
<List />
)
}
}
class List extends React.Component{
render(){
return(
<div class="row">
// populate props from Home component
</div>
)
}
}
我不怎麼做的是將響應數據傳遞給在這種情況下是List的子組件。
而且火力點的數據是這樣的:
object {
id:12131323,
firstName:'john',
address: {steet:'some street', city:'havana'}
}
object {
id:12221232,
firstName:'joe',
address:{steet:'big street', city:'dubai'}
}