【发布时间】:2021-06-26 00:10:28
【问题描述】:
我正在尝试在 Flatlist 中显示一项,但它没有显示任何内容。甚至 Flatlist 之外的项目也不会显示。我通常不使用 Class 组件,所以也许我错过了什么?
static navigationOption = ({ navigation }) => {
return {
scannedkey: navigation.getParam("itemId", null)
}
}
constructor(props){
super(props);
this.state={
productlist:[],
} }
async componentDidMount(scannedkey){
firebase.database().ref(`product/${scannedkey}`).on(
"value",
(snapshot) => {
var list = [];
snapshot.forEach((child) => {
list.push({
key: child.key,
title: child.title,
//details: child.val().details,
//price: child.val().price
});
});
this.setState({ productlist: list });
},
(error) => console.error(error)
);
}
componentWillUnmount() {
if (this.valuelistener_) {
this.valueRef_.off("value", this.valuelistener_)
}}
render() {
console.log(this.state.productlist)
return(
<View style={styles.container}>
<Text>Hey</Text>
<Text>{this.state.productlist.title}</Text>
</View>
);}}
这是我得到的错误:
Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 392608ms)
at node_modules\react-native\Libraries\LogBox\LogBox.js:117:10 in registerWarning
at node_modules\react-native\Libraries\LogBox\LogBox.js:63:8 in warnImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:36:4 in console.warn
at node_modules\expo\build\environment\react-native-logs.fx.js:18:4 in warn
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:226:6 in setTimeout
at node_modules\@firebase\database\dist\index.esm.js:99:8 in MemoryStorage
如果您能帮我找到解决方法,我将不胜感激。
【问题讨论】:
-
错字。您正在设置
produclist而不是productlist -
@jnpdx 修复了错字仍然无效我还添加了我从控制台日志中获得的内容。
标签: firebase react-native firebase-realtime-database react-native-flatlist react-native-firebase