ComponentWillmount Fetch returning Null?
ComponentWillmount Fetch returning Null?
我的应用程序总是在加载,当我放下一个调试器并将一个监视添加到变量列表&雷斯,我没有空。我不确定问题出在哪里,或者我是否正确地调试了它?
请给我建议。我试图通过将json加载到列表中来实现Loaded。
更新:我刚刚做了一个控制台日志,看到了数据
console.log(this.state.list);
var facemashTab = React.createClass({
getInitialState: function() {
return {
list: [],
currentIndex: 0
};
},
componentWillMount: function() {
fetch('https://randomuser.me/api/?results=5')
.then(res => res.json())
.then(res => this.setState({ list: res }));
},
render: function() {
var contents;
if (!this.state.list.length) {
contents = (
<View style={ styles.loading }>
<Text style={ styles.loadingText }>Loading</Text>
<ActivityIndicatorIOS />
</View>
)
} else {
contents = (
<View style={ styles.content }>
<Text>Loaded</Text>
</View>
)
}
return (
<View style={ styles.container }>
<View style={ styles.header }>
<Text style={ styles.headerText }>XXX</Text>
</View>
<View style={ styles.content }>
{ contents }
</View>
</View>
);
}
});
不确定这是否是问题所在,但根据我的理解,componentWillMount
中的setState
不会触发渲染阶段?你能试试componentDidMount
吗
相关文章:
- 数组在递归方法中设置为null
- 字符串在将其传递给另一个活动Android JavaScript时读取Null
- 无法获取属性'selectedIndex'的未定义引用或null引用
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- 来自文本输入null的html javascript变量
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- php代码在textbox更改事件上显示null
- 相同的RegExp返回不同的结果-第一次是正确的结果,第二次是null
- 在php中提交数据时,如果某些值为null,而某些值为非null,如何进行查询
- Window.parent and Window.top returning null
- JQuery Returning Null .next()
- ComponentWillmount Fetch returning Null?
- AJAX returning null XML
- CRM Xrm.Page.ui.formSelector.items.get() Returning Null
- document.getElementbyId() returning null
- `getElementById` returning null
- Dojo xhrGet only returning null
- document.getElementById(array[x]) returning null
- Dojo v1.6 dojo.attr() Returning NULL
- getElementById returning null