React-native-web: How to add Firebase to react-native-web project ?

Created on 23 Jan 2020  Â·  9Comments  Â·  Source: necolas/react-native-web

I am trying to use firebase api to use in react-native-web? How to do that?

Most helpful comment

Since the screen and components are shared across the Web, Android and iOS how can we configure it to use different libs. I tried to encapsulate analytics class for example and it ends up with a complicated structure.
For instance we need to use

import analytics from '@react-native-firebase/analytics';

for React Native - Android and iOS
for web it is firebase and used in fashion :-> firebase.analytics();

All 9 comments

I don't know, probably not different to a normal react web app, but this issue tracker isn't for support questions

I am trying to use firebase api to use in react-native-web? How to do that?

Have you got any solution for using firebase with react-native-web?

Use it like the same way firebase in use in create-react-app

On Sun, 10 May 2020, 10:57 pm Qadir Husainee, notifications@github.com
wrote:

I am trying to use firebase api to use in react-native-web? How to do that?

Have you got any solution for using firebase with react-native-web?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/necolas/react-native-web/issues/1526#issuecomment-626361390,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AGIZMCOJULVLPQZDZQFETBDRQ3PXNANCNFSM4KKZ7MRQ
.

Since the screen and components are shared across the Web, Android and iOS how can we configure it to use different libs. I tried to encapsulate analytics class for example and it ends up with a complicated structure.
For instance we need to use

import analytics from '@react-native-firebase/analytics';

for React Native - Android and iOS
for web it is firebase and used in fashion :-> firebase.analytics();

+1

Hi @ishaan-puniani
Can you please explain it more detail, may be with some example code? Thanks in advance ✋

I think he means that you use the module firebase/* for web instead of @react-native-firebase/analytics and flip between the two in order to go from native to web environments. It's a workaround that might be worth raising an issue with @react-native-firebase instead to see if they can cover adding the web environment (if they haven't already).

I sovled this problem with by creating 2 files:

  • firebaseAnalytics.js for mobile use react-native-firebase
  • firebaseAnalytics.web.js for web use firebase/analytics

@hungvu193 you okay to show the source of those?

Was this page helpful?
0 / 5 - 0 ratings