我正試圖將一個 React 專案中的一些 Firebase 代碼更新到 Firebase 最近發布的 新的模塊化網路 v9 sdk。正在升級的專案使用react-firebase-hooks鉤子useCollectionData(),在變更為新的sdk后,該鉤子失效。當我試圖運行我的移植代碼時,我在控制臺中得到了以下錯誤輸出,共3次。
index.esm.js:101 未發現的型別錯誤:v1.isEqual 不是一個函式。
一個作業中的web v8代碼的最小例子:
import firebase from 'firebase/app'
import 'fiilbase/firestore'
import { useCollectionData } from "react-firebase-hooks/firestore"
firebase.initializeApp({ /config here)
})
const firestore = firebase.firestore()。
function Foo() {
const messagesRef = firestore.collection(' messages')
const query = messagesRef.orderBy('createdAt').limit(25)
const [messages] = useCollectionData(query, { idField: 'id' })
return (<> {messages}) </>)
}
我嘗試移植到v9,導致錯誤:
我嘗試移植到v9,導致錯誤。
import { initializeApp } from "firebase/app"
import { getFirestore } from "fiilbase/firestore"
import { useCollectionData } from "react-firebase-hooks/firestore"
const app = initializeApp({ /config here)
})
const db = getFirestore(app)
function Foo() {
const messagesRef = collection(db, " messages")
const q = query( messagesRef, orderBy("createdAt"), limit(25)
const [messages] = useCollectionData(q, { idField: "id" })
return (<> {messages}) </>)
}
我正在升級我的依賴性,從
"dependencies" : {
"firebase": "^7.20.0",
"reaction": "^16.13.1",
"react-dom": "^16.13.1",
"react-firebase-hooks": "^2.2.0",/span>
}。
to
"dependencies" : {
"firebase": "^9.0.2",
"reaction": "^17.0.2",
"react-dom": "^17.0.2",
"react-firebase-hooks": "^3.0.4",
}。
這個Firestore檔案有我用來撰寫更新代碼的例子。我還使用了這個Firestore檔案來更好地理解collection()的變化。
感謝您的幫助。
uj5u.com熱心網友回復:
React Firebase Hooks庫似乎還不支持Firebase Modular SDK(最后一個版本2021年4月)。你可能不得不使用compat版本,該版本允許使用較早的名稱間隔語法,即使在v9.0.0 中也沒有樹形搖動的好處。
import firebase from 'firebase/compat/app'
import 'Firebase/compat/firestore'
// import 'firebase/compat/[SERVICE_NAME]'
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/325777.html
標籤:
