Reputation: 27
I have already installed and import firebase in the project, the code looks like this:
componentWillMount(){
var config = {
apiKey: "***************************",
authDomain: "configuracaofirebase-3a6ef.firebaseapp.com",
databaseURL: "https://configuracaofirebase-3a6ef.firebaseio.com",
projectId: "configuracaofirebase-3a6ef",
storageBucket: "configuracaofirebase-3a6ef.appspot.com",
messagingSenderId: "939162871117"
};
firebase.initializeApp(config);
}
salvarDados(){
var database = firebase.database();
database.ref("pontuacao").set("100");
}
render() {
return (
<View style={styles.container}>
<Button
onPress={ () => { this.salvarDados() } }
title="Salvar dados"
color="#841584"
accessibilityLabel="Salvar dados"
/>
<Text>Meu App</Text>
</View>
);
}
does not work when I call the "salvarDados" method
show this error:
typeError: undifined is not a function (evaluating '_app.default.database()')
Upvotes: 0
Views: 479
Reputation: 27
I solved it just by adding a new import:
import firebase from '@firebase/app';
import '@firebase/database';
Upvotes: 1
Reputation: 901
Try to remove the {} around the function call:
onPress={ () => { this.salvarDados() }
Will become:
onPress={ () => this.salvarDados() }
Upvotes: 0