一直在处理React项目,并且在安装它时在我的一个屏幕中,我的按钮的onPress在开始时就被激活,因此无法使用。在onPress激活功能时整个事件崩溃之后,发现了这一点(无法按下屏幕上的任何内容,包括选项卡,屏幕上也没有任何内容,因此将其更改为控制台日志,我可以看到按钮只是在开始。没有收到任何错误消息。
componentDidMount
componentDidMount = async () => {
var uid = firebase.auth().currentUser.uid
var foo= []
var foobyDoo= []
var i = 0;
// get firebase stuff
var arrayWithKeys = []
i = 0;
while (i < monthYearArray.length) {
arrayWithKeys.push([i, monthYearArray[i]])
i++
}
this.setState({
monthsAndYears: arrayWithKeys,
firebaseArray: arrayToSet,
})
}
渲染
render() {
return (
<ScrollView contentContainerStyle={{
flex: -1,
justifyContent: 'space-between'
}}>
{this.state.monthsAndYears.map((item) => (
<Button
key={item[0]}
title={this.state.monthIntMap[item[1].slice(0, 2)] + " " + item[1].slice(3,)}
onPress={this.someFunction} //This crashes the whole thing, if its changed to console.log
// then it will log upon mounting and afterwords the buttons are useless
/>
))
}
</ScrollView>
);
};
}
谢谢