我嘗試連接到firebaseby react native。這是代碼
import React, {Component} from 'react'
import {View} from 'react-native'
import Card from './card'
import { initializeApp } from 'firebase/app'
import firebase from 'firebase/compat/app'
const firebaseConfig = {
apiKey: "",
authDomain: "tinderclone-99d8e.firebaseapp.com",
projectId: "tinderclone-99d8e",
storageBucket: "tinderclone-99d8e.appspot.com",
messagingSenderId: "264605926507",
appId: "1:264605926507:web:c9309a6669322ef6839d2e",
databaseURL:''
};
firebase.initializeApp(firebaseConfig)
export default class App extends Component {
state = {
profileIndex: 0,
}
componentWillMount() {
firebase.database().ref().child('users').once('value', (snap) => {
console.log('Data', snap.val())
})
}
nextCard = () => {
this.setState({profileIndex: this.state.profileIndex 1})
}
render() {
const {profileIndex} = this.state
return (
<View style={{flex:1}}>
{profiles.slice(profileIndex, profileIndex 3).reverse().map((profile) => {
return (
<Card
key={profile.id}
profile={profile}
onSwipeOff={this.nextCard}
/>
)
})}
</View>
)
}
}
const profiles = [
{
id: '259389830744794',
name: 'Candice',
birthday: '10/18/1986',
bio: 'Supermodel',
},
{
id: '720115413',
name: 'Alessandra',
birthday: '1/10/1989',
bio: 'Dancer',
},
{
id: '169571172540',
name: 'Miranda',
birthday: '12/12/1983',
bio: 'Doctor',
},
{
id: '1476279359358140',
name: 'Alissa',
birthday: '2/11/1990',
bio: 'Comedian',
},
{
id: '1140849052644433',
name: 'Behati',
birthday: '3/23/1991',
bio: 'Developer',
},
{
id: '912478262117011',
name: 'Rosie',
birthday: '9/4/1989',
bio: 'Artist',
},
{
id: '173567062703796',
name: 'Kendall',
birthday: '8/17/1992',
bio: 'Truck Driver',
},
]
這是資料庫

這是錯誤
While trying to resolve module `firebase` from file `C:\Users\PC\Desktop\de\App.js`, the package `C:\Users\PC\Desktop\de\node_modules\firebase\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`C:\Users\PC\Desktop\de\node_modules\firebase\index`. Indeed, none of these files exist:
我已經firebase通過npm
我嘗試安裝run npm install并通過搜索其他人的答案重新開始 npm start 他們的答案對我不起作用。2021年,firebase和以前不一樣了。我不知道如何解決這個問題有人可以幫助我嗎
uj5u.com熱心網友回復:
您import * as firebase from 'firebase'在檔案頂部匯入..嘗試匯入此行并告訴我它是否有效。
import firebase from "firebase/compat/app";
一些路徑firebase很久以前就發生了變化,所以如果您正在觀看遺留代碼片段,您可能會遇到錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/347855.html
上一篇:“谷歌地圖”導航應用
