in src/firebase.ts [80:109]
export function useEmulatedFirebaseApp(
name: string,
config?: object,
initialize?: (app: firebase.app.App) => void
): firebase.app.App | undefined {
const { projectId } = useConfig();
const [app, setApp] = useState<firebase.app.App | undefined>();
useEffect(() => {
if (!app) {
const app = firebase.initializeApp(
{ ...config, projectId },
`${name} component::${Math.random()}`
);
applyAdminAuth(app);
initialize?.(app);
setApp(app);
}
return () => {
if (app) {
setApp(undefined);
// Errors may happen if app is already deleted. Ignore them.
app.delete().catch(() => {});
}
};
}, [app, name, config, projectId, initialize]);
return app;
}