You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0c0f114
Browse filesBrowse the repository at this point in the historyBrowse files
docs: fix emulator setup example to prevent double-initialization (#734)
* docs: fix emulator setup example to prevent double-initialization
Calling connect*Emulator() in a React component body causes 'Firestore has
already been started' errors on re-renders. Show two correct patterns:
module-level initialization (preferred) and a useRef guard for component-level
initialization.
Fixes#459
* docs: drop component-level useRef emulator example, recommend module-level init
* docs: note that firebaseConfig= prop makes emulator setup difficult, prefer firebaseApp=
Copy file name to clipboardExpand all lines: docs/use.md
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,37 +97,41 @@ SDK not found. useSdk must be called from within a provider
97
97
98
98
### Connect to the Firebase Local Emulator Suite
99
99
100
-
Connect a product SDK to the emulator before passing it to a provider. For example, to connect to the Auth and Realtime Database emulators:
100
+
Connect emulators to the SDK instances **before** passing them to providers. The safest pattern is to initialize outside of React entirely, which guarantees `connect*Emulator()` only runs once, regardless of re-renders or remounts:
This pattern requires passing `firebaseApp={app}` to `FirebaseAppProvider` so you own the app instance at module level. If you are currently using `firebaseConfig={...}` on `FirebaseAppProvider`, switch to initializing the app yourself with `initializeApp()` and passing it via `firebaseApp=`. The `firebaseConfig=` prop is a convenience shortcut, but it gives reactfire ownership of the app instance, which makes emulator setup (and anything else that needs the app before React renders) unnecessarily difficult.
134
+
131
135
Learn more about the Local Emulator Suite in the [Firebase docs](https://firebase.google.com/docs/emulator-suite/connect_and_prototype).
0 commit comments