0
0
React Nativemobile~20 mins

Firebase setup (@react-native-firebase) in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Firebase Initialization Behavior
After correctly installing and configuring @react-native-firebase/app, what will be the output of this code snippet in a React Native app?
React Native
import React from 'react';
import {Text, View} from 'react-native';
import firebase from '@react-native-firebase/app';

export default function App() {
  const isInitialized = firebase.apps.length > 0;
  return (
    <View>
      <Text>{isInitialized ? 'Firebase Initialized' : 'Firebase Not Initialized'}</Text>
    </View>
  );
}
ADisplays 'Firebase Initialized' on the screen
BDisplays 'Firebase Not Initialized' on the screen
CApp crashes with a runtime error
DDisplays a blank screen with no text
Attempts:
2 left
💡 Hint
Check if the firebase.apps array contains initialized apps after setup.
📝 Syntax
intermediate
1:30remaining
Correct Import for Firebase Firestore
Which import statement correctly imports Firestore from @react-native-firebase for use in a React Native app?
Aimport {firestore} from '@react-native-firebase/app';
Bimport firestore from '@react-native-firebase/firestore';
Cimport Firestore from '@react-native-firebase/firestore';
Dimport firebase from '@react-native-firebase/firestore';
Attempts:
2 left
💡 Hint
Check the official package name for Firestore in react-native-firebase.
lifecycle
advanced
2:00remaining
Effect of Missing GoogleService-Info.plist or google-services.json
What happens if you run a React Native app with @react-native-firebase/app installed but forget to add the GoogleService-Info.plist (iOS) or google-services.json (Android) files?
AFirebase initializes but throws runtime errors when accessing services
BFirebase initializes silently but no services work properly
CApp crashes immediately on startup with a native error
DApp runs normally without any Firebase functionality
Attempts:
2 left
💡 Hint
Think about what Firebase needs to connect to your project.
navigation
advanced
2:30remaining
Navigating After Firebase Auth State Change
In a React Native app using @react-native-firebase/auth, which code snippet correctly listens for user sign-in state changes and navigates to 'Home' screen when signed in?
A
useEffect(() =&gt; {
  const unsubscribe = auth().onAuthStateChanged(user =&gt; {
    if (!user) navigation.navigate('Home');
  });
  return unsubscribe;
}, []);
B
useEffect(() =&gt; {
  auth().onAuthStateChanged(user =&gt; {
    if (user) navigation.navigate('Home');
  });
}, []);
C
auth().onAuthStateChanged(user =&gt; {
  if (user) navigation.navigate('Home');
});
D
useEffect(() =&gt; {
  const unsubscribe = auth().onAuthStateChanged(user =&gt; {
    if (user) navigation.navigate('Home');
  });
  return unsubscribe;
}, []);
Attempts:
2 left
💡 Hint
Remember to clean up listeners in useEffect to avoid memory leaks.
🔧 Debug
expert
3:00remaining
Debugging Firebase Module Not Found Error
You installed @react-native-firebase/app and @react-native-firebase/auth, but when running your React Native app, you get the error: "Module '@react-native-firebase/auth' not found". What is the most likely cause?
AYou did not import auth from '@react-native-firebase/app' correctly
BYou need to restart the Metro bundler only
CYou forgot to run 'pod install' in the ios directory after installing the package
DYou must add google-services.json and GoogleService-Info.plist files
Attempts:
2 left
💡 Hint
Think about native module linking steps for iOS after adding new packages.