我想用react by this指令连接firebase中的实时数据库https://react-firebase-js.com/docs/react-firebase-realtime-database/getting-started
但是当我使用";FirebaseDatabaseNode";我收到这个错误。
我已经用这个插件成功地实现了身份验证。
我的app.js
import './App.css';
import firebase from "firebase/app";
import "firebase/auth";
import Home from './components/Home';
import React from 'react';
import Login from './components/login/Login';
import { FirebaseAuthConsumer, FirebaseAuthProvider } from '@react-firebase/auth';
import { FirebaseDatabaseProvider, FirebaseDatabaseNode } from "@react-firebase/database";
function App() {
let _firebaseConfig = {
apiKey: "My apiKey",
authDomain: "my authDomain",
databaseURL: "my databaseURL",
projectId: "my projectid",
storageBucket: "my storageBucket",
messagingSenderId: "my messagingSenderId",
appId: "my appId",
measurementId: "my measurementId"
};
return (
<FirebaseAuthProvider firebase={firebase} {..._firebaseConfig}>
{
<FirebaseDatabaseProvider firebase={firebase} {..._firebaseConfig}>
<FirebaseDatabaseNode
path="exchange_rate/"
// limitToFirst={this.state.limit}
// orderByKey
// orderByValue={"created_on"}
>
{d => {
return (
<React.Fragment>
<pre>Path {d.path}</pre>
<pre style={{ height: 300, overflow: "auto" }}>
Value {(d.value)}
</pre>
</React.Fragment>
);
}}
</FirebaseDatabaseNode>
</FirebaseDatabaseProvider>
}
</FirebaseAuthProvider>
);
}
export default App;
尝试导入数据库模块本身
import "firebase/database"