Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic usage of @react-native-firebase/admob gives: "TypeError: (0, _admob.default) is not a function". Is it deprecated? or Why doesnt work?

Is @react-native-firebase/admob deprecated? or just.. Why it doesn't work?

I am using @react-native-firebase/admob (https://rnfb-docs.netlify.app/admob/usage). Everything works fine before to use "admob()". When I add admob() to the code appears this error:

"TypeError: (0, _admob.default) is not a function"

Do someone know why?

My code below (basic usage):

import React from 'react';
import { Text, View} from 'react-native';
import admob, { MaxAdContentRating } from '@react-native-firebase/admob';
import { InterstitialAd, RewardedAd, BannerAd, TestIds } from '@react-native- 
firebase/admob';
import { BannerAdSize} from '@react-native-firebase/admob';



class App extends React.Component{

componentDidMount(){

// this was taked of official page: https://rnfb-docs.netlify.app/admob/usage#installation
admob()
  .setRequestConfiguration({
    // Update all future requests suitable for parental guidance
    maxAdContentRating: MaxAdContentRating.PG,

    // Indicates that you want your content treated as child-directed for purposes of COPPA.
    tagForChildDirectedTreatment: true,

    // Indicates that you want the ad request to be handled in a
    // manner suitable for users under the age of consent.
    tagForUnderAgeOfConsent: true,
  })
  .then(() => {
    // Request config successfully set!
  });
 }
render(){
return(
  <View style={{
    alignItems:"center", 
    justifyContent:"center",
    height:"100%"}}>
    <Text style={{color:"black"}}>
      Hola
    </Text>
    <BannerAd 
      unitId={TestIds.BANNER} 
      size={BannerAdSize.FULL_BANNER} />
  </View>
  )
 }
}
 export default App;


   
like image 290
Mauro Elias Avatar asked Jan 24 '23 08:01

Mauro Elias


1 Answers

Despite @CodeJoe Answer, I still got confused by different Documentations for the React Native Firebase that where around, hence I spend lots of time and energy to get around it.

I open an issue here where is confirmed that Google removed the AdMob Package since v11.5.0.

AdMob is no longer in Firebase APIs, so this module no longer wraps it, there is no documentation to correct. However it did exist as recently as v11.5.0 here and if you browse the repository at that point, you may consider the e2e tests for AdMob at the time a primer on "How To Use AdMob" https://github.com/invertase/react-native-firebase/tree/0217bff5cbbf233d7915efb4dbbdfe00e82dff23/packages/admob/e2e


Please, don't be like me and check the correct Documentation and website:

Correct

https://rnfirebase.io

Wrong Wrong Wrong, this refers to an older verison

https://rnfb-docs.netlify.app


The internet has a long memory, so there are stale copies of the docs out and about yes, but rnfirebase.io is always the official and current doc site

Admob was removed completely from the firebase ecosystem by Google so it does not exist here no. There are some community packages for it, our v11.5 version that has it, and we hope to peel our implementation out and update it for the community but it takes time and we are unfortunately still backlogged on official firebase apis, so it has not happened yet


So for AdMob solution I would use another Library, and use react-native-firebase for the Solutions that they currently provide

Alternative Library (August 2021)

DISCLAIMER

  • React Native Firebase is a great library still for the other packages they provide (Firebase, Analitycs...) and the Admob version 11.5 is still a solution. These are just suggestion for alternatives for Admob.
  • react-native-admob-alpha Simple and fresh library, recently updated.
  • react-native-admob-native-ads Another brand new library, they implement Admob Native Advanced Ads.
  • Expo AdMob (Available also for bare React-Native Projects)
like image 159
Federico Baù Avatar answered Jan 26 '23 21:01

Federico Baù