I have installed Firebase with npm in Firebase, but I don’t know what happens with this error.
File FIREBASE.js
JavaScript
x
20
20
1
// Import the functions you need from the SDKs you need
2
import { initializeApp } from "firebase/app";
3
// TODO: Add SDKs for Firebase products that you want to use
4
// https://firebase.google.com/docs/web/setup#available-libraries
5
6
// Your web app's Firebase configuration
7
const firebaseConfig = {
8
apiKey: "AIzaSyAd2EBoYYCRWEc3oClZTV3Wo-TiQkM2MgQ",
9
authDomain: "crud-react-26836.firebaseapp.com",
10
databaseURL: "https://crud-react-26836-default-rtdb.asia-southeast1.firebasedatabase.app",
11
projectId: "crud-react-26836",
12
storageBucket: "crud-react-26836.appspot.com",
13
messagingSenderId: "741718079918",
14
appId: "1:741718079918:web:1566301b46c4448c8c703f"
15
};
16
17
// Initialize Firebase
18
const FIREBASE = initializeApp(firebaseConfig);
19
export default FIREBASE;
20
TambahKontak.js
JavaScript
1
11
11
1
import React, { Component } from 'react'
2
import { StyleSheet, View, TouchableOpacity, Text, Alert } from 'react-native'
3
import { InputData } from '../../component'
4
import { FIREBASE } from '../../config/FIREBASE'
5
6
onSubmit = () => {
7
if (this.state.nama && this.state.nomorHP && this.state.alamat) {
8
console.log("Masuk Submit");
9
console.log(this.state);
10
const kontakReferensi = FIREBASE.database().ref('kontak');
11
Advertisement
Answer
You aren’t using the new Modular/Functional syntax which is included from version 9.0.0+
. You would have to rewrite your code to follow the new syntax:
JavaScript
1
5
1
import { getDatabase } from "firebase/database"
2
3
const dbRef = ref(getDatabase());
4
const snapshot = await get(child(dbRef, 'kontak'))
5
If you want to use the existing code (with older syntax) then use compat
version by changing the imports to:
JavaScript
1
7
1
import firebase from 'firebase/compat/app'
2
import 'firebase/compat/database'
3
import 'firebase/compat/[SERVICE_NAME]'
4
5
const FIREBASE = firebase.initializeApp(firebaseConfig);
6
export default FIREBASE;
7
I’d recommend using the new version and following the documentation for learning more about it.