react-native - that.setState 不是函数。(expo react native)
问题描述
这是我在课堂上的功能:
loadFeed = () => {
this.setState=({
refresh: true,
collection: []
});
var that = this;
database.ref('collection').orderByChild('date').once('value').then(function(snapshot) {
const exists = (snapshot.val() !== null);
if(exists) data = snapshot.val();
var temp = that.state.employees;
for(var item in data){
var Obj = data[photo];
database.ref('users').child(Obj.name).once('value').then(function(snapshot){
const exists = (snapshot.val() !== null);
if(exists) data = snapshot.val();
temp.push({
id: key,
name: Obj.name
});
that.setState({
refresh: false,
loading: false
});
}).catch(error => console.log(error));
}
}).catch(error => console.log(error));
}
在上面的代码中,我收到此错误:
that.setState 不是函数。
(In 'that.setState({ refresh: false, loading: false })', 'that.setState' is an instance of Object)
解决方案
this.setState=({
refresh: true,
collection: []
});
应该
this.setState({
refresh: true,
collection: []
});
推荐阅读
- powershell - 为什么从 Powershell switch 语句中的变量进行奇怪的赋值?
- reactjs - React Native 如何在应用程序中保存图像?
- c - 构建 FreeRDP 并安装错误:字段“des3_ctx”的类型不完整
- linux - 恢复无限嵌套/递归的 tmux 会话?
- c++ - 读取文件到 istream 替换类变量
- java - LibGDX 浮动与相机位置导致黑线与平铺地图
- java - 检查下一个要保存的输入是否在这些范围内
- class - fortran中的多态性
- android - 在 Android 生命周期中我应该在哪里使用 getIntent()
- python - if 函数的迭代器返回错误