我有此代码(用于react-native),我尝试使用它来将数据保存在火基数据库中,但是它不起作用,并且不会显示任何错误,您能帮我知道吗有什么问题。
import React, {Component} from 'react';
import {Platform, StyleSheet, Text,TextInput, View,Image,Button,TouchableOpacity} from 'react-native';
import firebase from '@firebase/app';
import '@firebase/auth';
import '@firebase/database';
//import firebase from 'firebase';
const config = {
//firebase connection
};
firebase.initializeApp(config);
export default class App extends Component{
constructor(props){
super(props)
this.state={
message:''
}this.addItem= this.addItem.bind(this);}
addItem(){
if(!this.state.message) return;
const newMessage= firebase.database().ref().child("messages").push();
newMessage.set(this.state.message, ()=>this.setState({message: ''}))
}
render(){
return(
<View>
<TextInput placeholder='enter text'
onChangeText={(text)=> this.setState({message: text})} />
<Button title='send' onPress={this.addItem} />
</View> );}}