查詢 Firebase 后,我似乎無法弄清楚如何設定 useState。我需要 BOX 等于除管理員之外的所有人的“公共 URL”。
import { auth } from "../firebase";
...
const [BOX, setBox] = useState('');
useEffect(() => {
if (auth.currentUser?.email === "[email protected]") {
setBox("https://admin/link");
} else {
setBox("https://public/link");
}
},[auth]);
錯誤總是不同的。有時它回傳“...空鏈接”,有時回傳“網路請求失敗”。有時它確實顯示了正確的資料,但是當我重繪 螢屏時它會遇到錯誤之一。
這是我的firebase檔案
// Import the functions you need from the SDKs you need
import * as firebase from "firebase";
import 'firebase/firestore';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
...
};
// Initialize Firebase
let app;
if (firebase.apps.length === 0) {
app = firebase.initializeApp(firebaseConfig);
} else {
app = firebase.app()
}
const auth = firebase.auth();
const dbFirebase = app.firestore();
export {auth, dbFirebase};
uj5u.com熱心網友回復:
您不能在 if 陳述句中使用鉤子...
const [box, setBox] = useState('');
useEffect(() => {
if (auth.currentUser?.email === "[email protected]") {
setBox("https://admin/link");
} else {
setBox("https://public/link");
}
},[auth]);
uj5u.com熱心網友回復:
對于 firebase 9,您需要像下面這樣配置它:
import { initializeApp } from 'firebase/app'
import { getAuth } from 'firebase/auth'
const firebaseConfig = {...}
initializeApp(firebaseConfig)
export const auth = getAuth()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/461566.html
