几乎所有内容都在标题上,请参阅下面的代码
saveData() {
let favdata = this.state.UserInput;
firebase.database().ref(`/favorites/`)
.push({ favdata })
.then(() => {
alert('Data saved!')
});
};
该函数无法读取状态,顺便说一句,我收到此错误:
undefined is not an object (evaluating 'this.state.UserInput')
最佳答案
将您的函数正确绑定(bind)到 this
例如,如下所示:
saveData = () => {
// function here
}
以下是有关同一主题的更多 Material :https://reactjs.org/docs/handling-events.html
关于javascript - Firebase 推送适用于 componentDidMount 而不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48726697/