【发布时间】:2021-12-18 11:18:04
【问题描述】:
我尝试通过react native 连接到firebase。
这是代码
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:
我已经通过npm 安装了firebase
我尝试run npm install 和 npm 通过搜索其他答案重新开始
他们的回答对我不起作用。
2021年,firebase和以前不一样了。
我不知道如何解决这个问题
有人可以帮我吗
【问题讨论】:
标签: android reactjs firebase react-native