当我控制台登录状态它返回未定义,但在我的反应开发工具,我可以看到结果数组。 这是组件:反应组件未更新状态
var Categorias = React.createClass({
getInitialState: function() {
return {
items: []
};
},
componentWillMount: function(){
var firebaseRef = new Firebase("https://rapifood.firebaseio.com/categorias");
firebaseRef.on("child_added", function(dataSnapshot) {
var items= [];
items.push(dataSnapshot.val());
this.setState({
items: items
});
}.bind(this));
},
componentDidMount: function() {
console.log(this.state.items);
},
我在做什么错?
你可能想尝试把'console.log'在渲染功能。在'componentDidMount'被触发时,不确定数据是否存在 – pmilla1606