I tried to use the firebase, but it does not have database function which is required to change, remove, or retrieve data from the server (Firebase Realtime Database). I think I install the firebase correctly because when I console.log firebase after importing it, it shows an object.
I tried the following code:
import React, { Component } from "react"; import classes from "./Body.module.css" import axios from "../../axios"; import Aux from "../../hoc/Auxiliary/Auxiliary"; import firebase from "firebase/app"; import "firebase/analytics"; import "firebase/auth"; import "firebase/firestore"; const firebaseConfig = { apiKey: "AIzaSyCjz2XRLma2GtEfW2doYBXjyrZQhYyKTc0", authDomain: "todolist-2d8de.firebaseapp.com", databaseURL: "https://todolist-2d8de-default-rtdb.firebaseio.com", projectId: "todolist-2d8de", storageBucket: "todolist-2d8de.appspot.com", messagingSenderId: "634814381180", appId: "1:634814381180:web:5d6e3a5465276f83921df9", measurementId: "G-V4XB270M1E" }; firebase.initializeApp(firebaseConfig); class Body extends Component{ state = {... } setHandler = () =>{ console.log(firebase); } ... } After calling the setHandler function, I got this object:
{__esModule: true, initializeApp: ƒ, app: ƒ, registerVersion: ƒ, setLogLevel: ƒ, …}
INTERNAL: {components: Map(14), registerComponent: ƒ, removeApp: ƒ, useAsService: ƒ, createFirebaseNamespace: ƒ, …}
SDK_VERSION: "8.0.1"
User: ƒ Im(a, b, c)
analytics: ƒ (appArg)
app: ƒ app(name)
apps: (...)
auth: ƒ (appArg)
default: {__esModule: true, initializeApp: ƒ, app: ƒ, registerVersion: ƒ, setLogLevel: ƒ, …}
firestore: ƒ (appArg)
initializeApp: ƒ ()
installations: ƒ (appArg)
onLog: ƒ onLog(logCallback, options)
registerVersion: ƒ registerVersion(libraryKeyOrName, version, variant)
setLogLevel: ƒ setLogLevel(level)
__esModule: true
get apps: ƒ getApps()
proto: Object
As you see, there is no such a field called database, which is what I need. Anyone please have an idea how to fix it?
It must be able to work in the following way:
function writeUserData(userId, name, email, imageUrl) { firebase.database().ref('users/' + userId).set({ username: name, email: email, profile_picture : imageUrl }); }
没有评论:
发表评论