Home > front end >  database is not function in react native firebase
database is not function in react native firebase

Time:11-18

this question is not duplicate for firebase.database is not function. I installed firebase and import as follow

import React, { Component } from 'react'
import { View } from 'react-native'
import Card from '../components/card'
import firebase from 'firebase/compat/app'
import database from 'firebase/compat/database'

export default class Home extends Component {

  state = {
    profileIndex: 0,
    profiles: [],
  }

  UNSAFE_componentWillMount() {
    firebase.database().ref().child('Users').once('value', (snap) => {
      let profiles = []
      snap.forEach((profile) => {
        const {name, bio, birthday, id} = profile.val()
        profiles.push({name, bio, birthday, id})
      })
      this.setState({profiles})
    })
  }

when not import this

import database from 'firebase/compat/database'

show error as

 firebase.daatabase is not function

but when import this

import database from 'firebase/compat/database'

error is gone and work but actually database is not using in code I want to know the solution for this How can use this method

 firebase.database()

what need to import in react native thanks

CodePudding user response:

https://rnfirebase.io/database/usage

Installation

@react-native-firebase/app
@react-native-firebase/database

pod install

cd ios/ && pod install && cd ..
import database from '@react-native-firebase/database';

  • Related