我正在使用 React hooks + firebase。
在 firebase 中,我创建了一个名为“projects”的集合
当我尝试控制台记录数据时:
const Dashboard = () => {
const { firebase } = useContext(GlobalContext);
return (
<div className="container">
{console.log(firebase.db.collection("projects"))}
</div>
);
};
我得到以下对象:
应该看不到我的数据吗?
以下是我设置的 Firebase 和上下文
firebase.js
import app from "firebase/app";
import "firebase/auth";
import "firebase/firebase-firestore";
const config = {//mydata}
class Firebase {
constructor() {
app.initializeApp(config);
this.auth = app.auth();
this.db = app.firestore();
}
}
export default new Firebase();
上下文.js
import React, { useReducer } from "react";
import { projectReducer } from "./reducers";
import firebase from "../components/firebase/firebase";
export const GlobalState = props => {
const [projects, setProjects] = useReducer(projectReducer, []);
return (
<GlobalContext.Provider
value={{
projects,
firebase
}}
>
{props.children}
</GlobalContext.Provider>
);
};