title: ReactNative initialize Firebase at app start?
body: <p>I have a app.js file, in which I'm creating my <code>NavigationContainer</code> and adding in some screens and calling a function called <code>init</code> (from my firebase.js file, see below) to initialize my app for Firebase.</p>
  <p>I also got a LoginScreen.js file, in which I'm handling login / register processes with firebase. If the user is logged in, the app loads the HomeScreen.js file immediatly. The firebase config is in a seperate file (firebase.js), which looks like this:</p>
  <pre><code>// Import the functions you need from the SDKs you need
  import { initializeApp } from 'firebase/app'
  import { getDatabase } from 'firebase/database'
  
  
  // TODO: Add SDKs for Firebase products that you want to use
  // https://firebase.google.com/docs/web/setup#available-libraries
  
  // Your web app's Firebase configuration
  const firebaseConfig = {
    // Imagine a config file here //
  };
  
  const init = () =&gt; {
    // Initialize Firebase
    const app = initializeApp(firebaseConfig);
    const db = getDatabase(app);
  }
  
  export { init };
  // somehow need to export db here
  </code></pre>
  <p>I'm now adding a todo list in a new screen the user can navigate to from my HomeScreen. Here I need the db from my firebase.js, because I want to save the objects there. However, the db seems to be &quot;undefined&quot;, probably because I can't access it because I haven't exported it from the firebase.js file.</p>
  <p>I tried removing the init function from my app.js, but that throws an &quot;No Firebase App has been created&quot; issue.</p>
  <p><strong>Question:</strong> How can I initialize my app in the firebase.js, make sure it get's called first AND have a working db exported in the same firebase.js file?</p>