@nardole/firebase-react 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -113
- package/dist/index.d.ts +64 -53
- package/dist/{index.mjs → main.js} +77 -75
- package/package.json +74 -55
- package/dist/index.d.mts +0 -53
- package/dist/index.js +0 -131
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
# @nardole/firebase-react
|
|
2
|
-
|
|
3
|
-
Elegant React bindings for @nardole/firebase-core. Provide the Firebase App via Context and access it anywhere with hooks. Works great in Micro‑Frontends thanks to the shared singleton under the hood.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@nardole/firebase-react)
|
|
6
|
-

|
|
7
|
-
[](#license)
|
|
8
|
-
[](https://react.dev/)
|
|
9
|
-
|
|
10
|
-
- Why
|
|
11
|
-
- Features
|
|
12
|
-
- Installation
|
|
13
|
-
- Quick Start
|
|
14
|
-
- Usage
|
|
15
|
-
- Provider
|
|
16
|
-
- Hook
|
|
17
|
-
- Micro‑Frontend (MFE)
|
|
18
|
-
- API
|
|
19
|
-
- Compatibility
|
|
20
|
-
- Troubleshooting
|
|
21
|
-
- License
|
|
22
|
-
|
|
23
|
-
## Why
|
|
24
|
-
Managing Firebase initialization across multiple React apps or MFEs is error‑prone. This package provides a tiny Provider and Hook built on a shared singleton, ensuring exactly one Firebase instance.
|
|
25
|
-
|
|
26
|
-
## Features
|
|
27
|
-
- FirebaseAppProvider to initialize and provide the app via React Context
|
|
28
|
-
- useFirebaseApp hook to access the current FirebaseApp instance
|
|
29
|
-
- Designed for MFEs — initialize once (even outside React) and reuse everywhere
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
- pnpm add @nardole/firebase-react @nardole/firebase-core firebase react react-dom
|
|
33
|
-
- npm install @nardole/firebase-react @nardole/firebase-core firebase react react-dom
|
|
34
|
-
- yarn add @nardole/firebase-react @nardole/firebase-core firebase react react-dom
|
|
35
|
-
|
|
36
|
-
## Quick Start
|
|
37
|
-
1. Wrap your application with the Provider using your Firebase options.
|
|
38
|
-
2. Use the Hook in child components to access the shared instance.
|
|
39
|
-
|
|
40
|
-
## Usage — Provider
|
|
41
|
-
```tsx
|
|
42
|
-
import { FirebaseAppProvider } from '@nardole/firebase-react';
|
|
43
|
-
|
|
44
|
-
export function AppRoot() {
|
|
45
|
-
return (
|
|
46
|
-
<FirebaseAppProvider
|
|
47
|
-
options={{
|
|
48
|
-
apiKey: 'YOUR_API_KEY',
|
|
49
|
-
authDomain: 'YOUR_AUTH_DOMAIN',
|
|
50
|
-
projectId: 'YOUR_PROJECT_ID',
|
|
51
|
-
appId: 'YOUR_APP_ID',
|
|
52
|
-
}}
|
|
53
|
-
>
|
|
54
|
-
<YourApp />
|
|
55
|
-
</FirebaseAppProvider>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Usage — Hook
|
|
61
|
-
```tsx
|
|
62
|
-
import { useFirebaseApp } from '@nardole/firebase-react';
|
|
63
|
-
|
|
64
|
-
export function AnyComponent() {
|
|
65
|
-
const app = useFirebaseApp();
|
|
66
|
-
// Use app with other firebase packages (auth, firestore, etc.)
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Micro‑Frontend (MFE)
|
|
72
|
-
Initialize the core service in the shell or any federated module, and React MFEs will reuse it.
|
|
73
|
-
```ts
|
|
74
|
-
// shell or any non-React mfe
|
|
75
|
-
import { firebaseService } from '@nardole/firebase-core';
|
|
76
|
-
firebaseService.init({ /* options */ });
|
|
77
|
-
```
|
|
78
|
-
```tsx
|
|
79
|
-
// inside a React MFE
|
|
80
|
-
import { FirebaseAppProvider, useFirebaseApp } from '@nardole/firebase-react';
|
|
81
|
-
|
|
82
|
-
// Option A — wrap with the provider (reuses existing instance)
|
|
83
|
-
<FirebaseAppProvider options={{ /* same options */ }}>
|
|
84
|
-
<YourApp />
|
|
85
|
-
</FirebaseAppProvider>
|
|
86
|
-
|
|
87
|
-
// Option B — if the provider isn’t available, you can still use the hook
|
|
88
|
-
const app = useFirebaseApp();
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## API
|
|
92
|
-
|
|
93
|
-
| Item | Props/Signature | Description | Notes/Errors |
|
|
94
|
-
| --- | --- | --- | --- |
|
|
95
|
-
| FirebaseAppProvider | <FirebaseAppProvider options: FirebaseOptions, name?: string, enableAnalytics?: boolean, enablePerformance?: boolean, enableRemoteConfig?: boolean, enableStorage?: boolean, enableAuth?: boolean, enableDatabase?: boolean, enableFirestore?: boolean> | React Provider that initializes and provides Firebase App via Context. It can also pre-instantiate and expose optional Firebase services via Context. | Internally calls firebaseService.init(options, name, true) when options/name change. Optional services are only available in Context if their respective enable flags are true. |
|
|
96
|
-
| useFirebaseApp | useFirebaseApp(): FirebaseApp | Hook to get the current FirebaseApp from Context. | Throws if used outside a FirebaseAppProvider: "Firebase app isn't found, did you forget to wrap your app in <FirebaseAppProvider>" |
|
|
97
|
-
| useAnalytics | useAnalytics(): Analytics | Hook to access Analytics from Context. | Throws if Provider not present or enableAnalytics not set. |
|
|
98
|
-
| usePerformance | usePerformance(): FirebasePerformance | Hook to access Performance from Context. | Throws if Provider not present or enablePerformance not set. |
|
|
99
|
-
| useRemoteConfig | useRemoteConfig(): RemoteConfig | Hook to access Remote Config from Context. | Throws if Provider not present or enableRemoteConfig not set. |
|
|
100
|
-
| useStorage | useStorage(): FirebaseStorage | Hook to access Storage from Context. | Throws if Provider not present or enableStorage not set. |
|
|
101
|
-
| useAuth | useAuth(): Auth | Hook to access Auth from Context. | Throws if Provider not present or enableAuth not set. |
|
|
102
|
-
| useDatabase | useDatabase(): Database | Hook to access Realtime Database from Context. | Throws if Provider not present or enableDatabase not set. |
|
|
103
|
-
| useFirestore | useFirestore(): Firestore | Hook to access Firestore from Context. | Throws if Provider not present or enableFirestore not set. |
|
|
104
|
-
|
|
105
|
-
## Compatibility
|
|
106
|
-
- Peer: react >=17, react-dom >=17, firebase ^12, @nardole/firebase-core ^1
|
|
107
|
-
|
|
108
|
-
## Troubleshooting
|
|
109
|
-
- Seeing "Firebase app already initialized" warnings/errors?
|
|
110
|
-
- Ensure your MFEs share the same options and app name, or rely on the @nardole/firebase-core singleton. The Provider uses `override` to safely update when props change.
|
|
111
|
-
|
|
112
|
-
## License
|
|
113
|
-
MIT
|
|
1
|
+
# @nardole/firebase-react
|
|
2
|
+
|
|
3
|
+
Elegant React bindings for @nardole/firebase-core. Provide the Firebase App via Context and access it anywhere with hooks. Works great in Micro‑Frontends thanks to the shared singleton under the hood.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@nardole/firebase-react)
|
|
6
|
+

|
|
7
|
+
[](#license)
|
|
8
|
+
[](https://react.dev/)
|
|
9
|
+
|
|
10
|
+
- Why
|
|
11
|
+
- Features
|
|
12
|
+
- Installation
|
|
13
|
+
- Quick Start
|
|
14
|
+
- Usage
|
|
15
|
+
- Provider
|
|
16
|
+
- Hook
|
|
17
|
+
- Micro‑Frontend (MFE)
|
|
18
|
+
- API
|
|
19
|
+
- Compatibility
|
|
20
|
+
- Troubleshooting
|
|
21
|
+
- License
|
|
22
|
+
|
|
23
|
+
## Why
|
|
24
|
+
Managing Firebase initialization across multiple React apps or MFEs is error‑prone. This package provides a tiny Provider and Hook built on a shared singleton, ensuring exactly one Firebase instance.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
- FirebaseAppProvider to initialize and provide the app via React Context
|
|
28
|
+
- useFirebaseApp hook to access the current FirebaseApp instance
|
|
29
|
+
- Designed for MFEs — initialize once (even outside React) and reuse everywhere
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
- pnpm add @nardole/firebase-react @nardole/firebase-core firebase react react-dom
|
|
33
|
+
- npm install @nardole/firebase-react @nardole/firebase-core firebase react react-dom
|
|
34
|
+
- yarn add @nardole/firebase-react @nardole/firebase-core firebase react react-dom
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
1. Wrap your application with the Provider using your Firebase options.
|
|
38
|
+
2. Use the Hook in child components to access the shared instance.
|
|
39
|
+
|
|
40
|
+
## Usage — Provider
|
|
41
|
+
```tsx
|
|
42
|
+
import { FirebaseAppProvider } from '@nardole/firebase-react';
|
|
43
|
+
|
|
44
|
+
export function AppRoot() {
|
|
45
|
+
return (
|
|
46
|
+
<FirebaseAppProvider
|
|
47
|
+
options={{
|
|
48
|
+
apiKey: 'YOUR_API_KEY',
|
|
49
|
+
authDomain: 'YOUR_AUTH_DOMAIN',
|
|
50
|
+
projectId: 'YOUR_PROJECT_ID',
|
|
51
|
+
appId: 'YOUR_APP_ID',
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<YourApp />
|
|
55
|
+
</FirebaseAppProvider>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage — Hook
|
|
61
|
+
```tsx
|
|
62
|
+
import { useFirebaseApp } from '@nardole/firebase-react';
|
|
63
|
+
|
|
64
|
+
export function AnyComponent() {
|
|
65
|
+
const app = useFirebaseApp();
|
|
66
|
+
// Use app with other firebase packages (auth, firestore, etc.)
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Micro‑Frontend (MFE)
|
|
72
|
+
Initialize the core service in the shell or any federated module, and React MFEs will reuse it.
|
|
73
|
+
```ts
|
|
74
|
+
// shell or any non-React mfe
|
|
75
|
+
import { firebaseService } from '@nardole/firebase-core';
|
|
76
|
+
firebaseService.init({ /* options */ });
|
|
77
|
+
```
|
|
78
|
+
```tsx
|
|
79
|
+
// inside a React MFE
|
|
80
|
+
import { FirebaseAppProvider, useFirebaseApp } from '@nardole/firebase-react';
|
|
81
|
+
|
|
82
|
+
// Option A — wrap with the provider (reuses existing instance)
|
|
83
|
+
<FirebaseAppProvider options={{ /* same options */ }}>
|
|
84
|
+
<YourApp />
|
|
85
|
+
</FirebaseAppProvider>
|
|
86
|
+
|
|
87
|
+
// Option B — if the provider isn’t available, you can still use the hook
|
|
88
|
+
const app = useFirebaseApp();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API
|
|
92
|
+
|
|
93
|
+
| Item | Props/Signature | Description | Notes/Errors |
|
|
94
|
+
| --- | --- | --- | --- |
|
|
95
|
+
| FirebaseAppProvider | <FirebaseAppProvider options: FirebaseOptions, name?: string, enableAnalytics?: boolean, enablePerformance?: boolean, enableRemoteConfig?: boolean, enableStorage?: boolean, enableAuth?: boolean, enableDatabase?: boolean, enableFirestore?: boolean> | React Provider that initializes and provides Firebase App via Context. It can also pre-instantiate and expose optional Firebase services via Context. | Internally calls firebaseService.init(options, name, true) when options/name change. Optional services are only available in Context if their respective enable flags are true. |
|
|
96
|
+
| useFirebaseApp | useFirebaseApp(): FirebaseApp | Hook to get the current FirebaseApp from Context. | Throws if used outside a FirebaseAppProvider: "Firebase app isn't found, did you forget to wrap your app in <FirebaseAppProvider>" |
|
|
97
|
+
| useAnalytics | useAnalytics(): Analytics | Hook to access Analytics from Context. | Throws if Provider not present or enableAnalytics not set. |
|
|
98
|
+
| usePerformance | usePerformance(): FirebasePerformance | Hook to access Performance from Context. | Throws if Provider not present or enablePerformance not set. |
|
|
99
|
+
| useRemoteConfig | useRemoteConfig(): RemoteConfig | Hook to access Remote Config from Context. | Throws if Provider not present or enableRemoteConfig not set. |
|
|
100
|
+
| useStorage | useStorage(): FirebaseStorage | Hook to access Storage from Context. | Throws if Provider not present or enableStorage not set. |
|
|
101
|
+
| useAuth | useAuth(): Auth | Hook to access Auth from Context. | Throws if Provider not present or enableAuth not set. |
|
|
102
|
+
| useDatabase | useDatabase(): Database | Hook to access Realtime Database from Context. | Throws if Provider not present or enableDatabase not set. |
|
|
103
|
+
| useFirestore | useFirestore(): Firestore | Hook to access Firestore from Context. | Throws if Provider not present or enableFirestore not set. |
|
|
104
|
+
|
|
105
|
+
## Compatibility
|
|
106
|
+
- Peer: react >=17, react-dom >=17, firebase ^12, @nardole/firebase-core ^1
|
|
107
|
+
|
|
108
|
+
## Troubleshooting
|
|
109
|
+
- Seeing "Firebase app already initialized" warnings/errors?
|
|
110
|
+
- Ensure your MFEs share the same options and app name, or rely on the @nardole/firebase-core singleton. The Provider uses `override` to safely update when props change.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { FirebaseOptions
|
|
11
|
-
import {
|
|
12
|
-
import { FirebasePerformance } from 'firebase/performance';
|
|
13
|
-
import {
|
|
14
|
-
import { FirebaseStorage } from 'firebase/storage';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
declare
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
import { Analytics } from '@firebase/analytics';
|
|
2
|
+
import { Analytics as Analytics_2 } from 'firebase/analytics';
|
|
3
|
+
import { Auth } from '@firebase/auth';
|
|
4
|
+
import { Auth as Auth_2 } from 'firebase/auth';
|
|
5
|
+
import { Database } from '@firebase/database';
|
|
6
|
+
import { Database as Database_2 } from 'firebase/database';
|
|
7
|
+
import { default as default_2 } from 'react';
|
|
8
|
+
import { FirebaseApp } from '@firebase/app';
|
|
9
|
+
import { FirebaseApp as FirebaseApp_2 } from 'firebase/app';
|
|
10
|
+
import { FirebaseOptions } from 'firebase/app';
|
|
11
|
+
import { FirebasePerformance } from '@firebase/performance';
|
|
12
|
+
import { FirebasePerformance as FirebasePerformance_2 } from 'firebase/performance';
|
|
13
|
+
import { FirebaseStorage } from '@firebase/storage';
|
|
14
|
+
import { FirebaseStorage as FirebaseStorage_2 } from 'firebase/storage';
|
|
15
|
+
import { Firestore } from '@firebase/firestore';
|
|
16
|
+
import { Firestore as Firestore_2 } from 'firebase/firestore';
|
|
17
|
+
import { JSX } from 'react/jsx-runtime';
|
|
18
|
+
import { RemoteConfig } from '@firebase/remote-config';
|
|
19
|
+
import { RemoteConfig as RemoteConfig_2 } from 'firebase/remote-config';
|
|
20
|
+
|
|
21
|
+
export declare const FirebaseAppContext: default_2.Context<FirebaseAppContextValue | undefined>;
|
|
22
|
+
|
|
23
|
+
declare type FirebaseAppContextValue = {
|
|
24
|
+
app: FirebaseApp_2;
|
|
25
|
+
analytics?: Analytics_2;
|
|
26
|
+
performance?: FirebasePerformance_2;
|
|
27
|
+
remoteConfig?: RemoteConfig_2;
|
|
28
|
+
storage?: FirebaseStorage_2;
|
|
29
|
+
auth?: Auth_2;
|
|
30
|
+
database?: Database_2;
|
|
31
|
+
firestore?: Firestore_2;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare function FirebaseAppProvider({ options, name, enableAnalytics, enablePerformance, enableRemoteConfig, enableStorage, enableAuth, enableDatabase, enableFirestore, children, }: FirebaseAppProviderProps): JSX.Element;
|
|
35
|
+
|
|
36
|
+
declare type FirebaseAppProviderProps = default_2.PropsWithChildren<{
|
|
37
|
+
options: FirebaseOptions;
|
|
38
|
+
name?: string;
|
|
39
|
+
enableAnalytics?: boolean;
|
|
40
|
+
enablePerformance?: boolean;
|
|
41
|
+
enableRemoteConfig?: boolean;
|
|
42
|
+
enableStorage?: boolean;
|
|
43
|
+
enableAuth?: boolean;
|
|
44
|
+
enableDatabase?: boolean;
|
|
45
|
+
enableFirestore?: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
export declare function useAnalytics(): Analytics;
|
|
49
|
+
|
|
50
|
+
export declare function useAuth(): Auth;
|
|
51
|
+
|
|
52
|
+
export declare function useDatabase(): Database;
|
|
53
|
+
|
|
54
|
+
export declare function useFirebaseApp(): FirebaseApp;
|
|
55
|
+
|
|
56
|
+
export declare function useFirestore(): Firestore;
|
|
57
|
+
|
|
58
|
+
export declare function usePerformance(): FirebasePerformance;
|
|
59
|
+
|
|
60
|
+
export declare function useRemoteConfig(): RemoteConfig;
|
|
61
|
+
|
|
62
|
+
export declare function useStorage(): FirebaseStorage;
|
|
63
|
+
|
|
64
|
+
export { }
|
|
@@ -1,10 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { firebaseService } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import React, { useRef, useMemo, useContext } from "react";
|
|
2
|
+
import { firebaseService } from "@nardole/firebase-core";
|
|
3
|
+
const FirebaseAppContext = React.createContext(void 0);
|
|
4
|
+
function FirebaseAppProvider({
|
|
5
|
+
options,
|
|
6
|
+
name,
|
|
7
|
+
enableAnalytics,
|
|
8
|
+
enablePerformance,
|
|
9
|
+
enableRemoteConfig,
|
|
10
|
+
enableStorage,
|
|
11
|
+
enableAuth,
|
|
12
|
+
enableDatabase,
|
|
13
|
+
enableFirestore,
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
const optionsRef = useRef(void 0);
|
|
17
|
+
const nameRef = useRef(void 0);
|
|
18
|
+
const value = useMemo(() => {
|
|
19
|
+
if (optionsRef.current !== options || nameRef.current !== name) {
|
|
20
|
+
firebaseService.init(options, name, true);
|
|
21
|
+
}
|
|
22
|
+
optionsRef.current = options;
|
|
23
|
+
nameRef.current = name;
|
|
24
|
+
return {
|
|
25
|
+
app: firebaseService.app,
|
|
26
|
+
analytics: enableAnalytics ? firebaseService.analytics : void 0,
|
|
27
|
+
performance: enablePerformance ? firebaseService.performance : void 0,
|
|
28
|
+
remoteConfig: enableRemoteConfig ? firebaseService.remoteConfig : void 0,
|
|
29
|
+
storage: enableStorage ? firebaseService.storage : void 0,
|
|
30
|
+
auth: enableAuth ? firebaseService.auth : void 0,
|
|
31
|
+
database: enableDatabase ? firebaseService.database : void 0,
|
|
32
|
+
firestore: enableFirestore ? firebaseService.firestore : void 0
|
|
33
|
+
};
|
|
34
|
+
}, [options, name]);
|
|
35
|
+
return /* @__PURE__ */ React.createElement(FirebaseAppContext.Provider, { value }, children);
|
|
36
|
+
}
|
|
37
|
+
function useAnalytics() {
|
|
38
|
+
const app = useContext(FirebaseAppContext);
|
|
39
|
+
if (!app || !app.analytics) {
|
|
40
|
+
throw new Error("Analytics is not enabled for this Firebase app");
|
|
41
|
+
}
|
|
42
|
+
return app.analytics;
|
|
43
|
+
}
|
|
44
|
+
function useAuth() {
|
|
45
|
+
const value = useContext(FirebaseAppContext);
|
|
46
|
+
if (!value || value.auth === void 0) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Firebase auth isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return value.auth;
|
|
52
|
+
}
|
|
53
|
+
function useDatabase() {
|
|
54
|
+
const value = useContext(FirebaseAppContext);
|
|
55
|
+
if (!value || value.database === void 0) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Firebase database isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return value.database;
|
|
61
|
+
}
|
|
8
62
|
function useFirebaseApp() {
|
|
9
63
|
const value = useContext(FirebaseAppContext);
|
|
10
64
|
if (!value || value.app === void 0) {
|
|
@@ -14,14 +68,14 @@ function useFirebaseApp() {
|
|
|
14
68
|
}
|
|
15
69
|
return value.app;
|
|
16
70
|
}
|
|
17
|
-
function
|
|
71
|
+
function useFirestore() {
|
|
18
72
|
const value = useContext(FirebaseAppContext);
|
|
19
|
-
if (!value || value.
|
|
73
|
+
if (!value || value.firestore === void 0) {
|
|
20
74
|
throw new Error(
|
|
21
|
-
"Firebase
|
|
75
|
+
"Firebase firestore isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
22
76
|
);
|
|
23
77
|
}
|
|
24
|
-
return value.
|
|
78
|
+
return value.firestore;
|
|
25
79
|
}
|
|
26
80
|
function usePerformance() {
|
|
27
81
|
const value = useContext(FirebaseAppContext);
|
|
@@ -50,67 +104,15 @@ function useStorage() {
|
|
|
50
104
|
}
|
|
51
105
|
return value.storage;
|
|
52
106
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
throw new Error(
|
|
66
|
-
"Firebase database isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return value.database;
|
|
70
|
-
}
|
|
71
|
-
function useFirestore() {
|
|
72
|
-
const value = useContext(FirebaseAppContext);
|
|
73
|
-
if (!value || value.firestore === void 0) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
"Firebase firestore isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
return value.firestore;
|
|
79
|
-
}
|
|
80
|
-
function FirebaseAppProvider({
|
|
81
|
-
options,
|
|
82
|
-
name,
|
|
83
|
-
enableAnalytics,
|
|
84
|
-
enablePerformance,
|
|
85
|
-
enableRemoteConfig,
|
|
86
|
-
enableStorage,
|
|
87
|
-
enableAuth,
|
|
88
|
-
enableDatabase,
|
|
89
|
-
enableFirestore,
|
|
90
|
-
children
|
|
91
|
-
}) {
|
|
92
|
-
const optionsRef = React2.useRef(void 0);
|
|
93
|
-
const nameRef = React2.useRef(void 0);
|
|
94
|
-
const value = React2.useMemo(() => {
|
|
95
|
-
if (optionsRef.current !== options || nameRef.current !== name) {
|
|
96
|
-
firebaseService.init(options, name, true);
|
|
97
|
-
}
|
|
98
|
-
optionsRef.current = options;
|
|
99
|
-
nameRef.current = name;
|
|
100
|
-
return {
|
|
101
|
-
app: firebaseService.app,
|
|
102
|
-
analytics: enableAnalytics ? firebaseService.analytics : void 0,
|
|
103
|
-
performance: enablePerformance ? firebaseService.performance : void 0,
|
|
104
|
-
remoteConfig: enableRemoteConfig ? firebaseService.remoteConfig : void 0,
|
|
105
|
-
storage: enableStorage ? firebaseService.storage : void 0,
|
|
106
|
-
auth: enableAuth ? firebaseService.auth : void 0,
|
|
107
|
-
database: enableDatabase ? firebaseService.database : void 0,
|
|
108
|
-
firestore: enableFirestore ? firebaseService.firestore : void 0
|
|
109
|
-
};
|
|
110
|
-
}, [options, name]);
|
|
111
|
-
return /* @__PURE__ */ React2.createElement(FirebaseAppContext.Provider, { value }, children);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export { FirebaseAppContext, FirebaseAppProvider, useAnalytics, useAuth, useDatabase, useFirebaseApp, useFirestore, usePerformance, useRemoteConfig, useStorage };
|
|
115
|
-
//# sourceMappingURL=index.mjs.map
|
|
116
|
-
//# sourceMappingURL=index.mjs.map
|
|
107
|
+
export {
|
|
108
|
+
FirebaseAppContext,
|
|
109
|
+
FirebaseAppProvider,
|
|
110
|
+
useAnalytics,
|
|
111
|
+
useAuth,
|
|
112
|
+
useDatabase,
|
|
113
|
+
useFirebaseApp,
|
|
114
|
+
useFirestore,
|
|
115
|
+
usePerformance,
|
|
116
|
+
useRemoteConfig,
|
|
117
|
+
useStorage
|
|
118
|
+
};
|
package/package.json
CHANGED
|
@@ -1,55 +1,74 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nardole/firebase-react",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@nardole/firebase-react",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"firebase",
|
|
6
|
+
"react",
|
|
7
|
+
"context",
|
|
8
|
+
"hooks",
|
|
9
|
+
"provider",
|
|
10
|
+
"analytics",
|
|
11
|
+
"performance",
|
|
12
|
+
"remote-config",
|
|
13
|
+
"storage",
|
|
14
|
+
"auth",
|
|
15
|
+
"database",
|
|
16
|
+
"firestore",
|
|
17
|
+
"micro-frontend",
|
|
18
|
+
"mfe",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Luiz Braga",
|
|
23
|
+
"email": "me@nardole.dev"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "tsc -b && vite build",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"preview": "vite preview",
|
|
31
|
+
"prepublishOnly": "yarn build"
|
|
32
|
+
},
|
|
33
|
+
"main": "dist/main.js",
|
|
34
|
+
"types": "dist/main.d.ts",
|
|
35
|
+
"module": "dist/main.js",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/main.d.ts",
|
|
39
|
+
"import": "./dist/main.js"
|
|
40
|
+
},
|
|
41
|
+
"./*": {
|
|
42
|
+
"types": "./dist/*.d.ts",
|
|
43
|
+
"import": "./dist/*.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public",
|
|
51
|
+
"registry": "https://registry.npmjs.org/"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/btmluiz/nardole-firebase",
|
|
56
|
+
"directory": "packages/firebase-react"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@nardole/firebase-core": "*",
|
|
60
|
+
"react": "*",
|
|
61
|
+
"react-dom": "*"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@nardole/firebase-core": "^0.0.14",
|
|
65
|
+
"@types/react": "^19.2.14",
|
|
66
|
+
"@types/react-dom": "^19.2.3",
|
|
67
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
68
|
+
"firebase": "^12.9.0",
|
|
69
|
+
"typescript": "^5.9.3",
|
|
70
|
+
"vite": "^7.3.1",
|
|
71
|
+
"vite-plugin-dts": "^4.5.4"
|
|
72
|
+
},
|
|
73
|
+
"packageManager": "yarn@4.10.3"
|
|
74
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as _firebase_firestore from '@firebase/firestore';
|
|
2
|
-
import * as _firebase_database from '@firebase/database';
|
|
3
|
-
import * as _firebase_auth from '@firebase/auth';
|
|
4
|
-
import * as _firebase_storage from '@firebase/storage';
|
|
5
|
-
import * as _firebase_remote_config from '@firebase/remote-config';
|
|
6
|
-
import * as _firebase_performance from '@firebase/performance';
|
|
7
|
-
import * as _firebase_analytics from '@firebase/analytics';
|
|
8
|
-
import * as _firebase_app from '@firebase/app';
|
|
9
|
-
import React from 'react';
|
|
10
|
-
import { FirebaseOptions, FirebaseApp } from 'firebase/app';
|
|
11
|
-
import { Analytics } from 'firebase/analytics';
|
|
12
|
-
import { FirebasePerformance } from 'firebase/performance';
|
|
13
|
-
import { RemoteConfig } from 'firebase/remote-config';
|
|
14
|
-
import { FirebaseStorage } from 'firebase/storage';
|
|
15
|
-
import { Auth } from 'firebase/auth';
|
|
16
|
-
import { Database } from 'firebase/database';
|
|
17
|
-
import { Firestore } from 'firebase/firestore';
|
|
18
|
-
|
|
19
|
-
declare function useFirebaseApp(): _firebase_app.FirebaseApp;
|
|
20
|
-
declare function useAnalytics(): _firebase_analytics.Analytics;
|
|
21
|
-
declare function usePerformance(): _firebase_performance.FirebasePerformance;
|
|
22
|
-
declare function useRemoteConfig(): _firebase_remote_config.RemoteConfig;
|
|
23
|
-
declare function useStorage(): _firebase_storage.FirebaseStorage;
|
|
24
|
-
declare function useAuth(): _firebase_auth.Auth;
|
|
25
|
-
declare function useDatabase(): _firebase_database.Database;
|
|
26
|
-
declare function useFirestore(): _firebase_firestore.Firestore;
|
|
27
|
-
|
|
28
|
-
type FirebaseAppProviderProps = React.PropsWithChildren<{
|
|
29
|
-
options: FirebaseOptions;
|
|
30
|
-
name?: string;
|
|
31
|
-
enableAnalytics?: boolean;
|
|
32
|
-
enablePerformance?: boolean;
|
|
33
|
-
enableRemoteConfig?: boolean;
|
|
34
|
-
enableStorage?: boolean;
|
|
35
|
-
enableAuth?: boolean;
|
|
36
|
-
enableDatabase?: boolean;
|
|
37
|
-
enableFirestore?: boolean;
|
|
38
|
-
}>;
|
|
39
|
-
declare function FirebaseAppProvider({ options, name, enableAnalytics, enablePerformance, enableRemoteConfig, enableStorage, enableAuth, enableDatabase, enableFirestore, children, }: FirebaseAppProviderProps): React.JSX.Element;
|
|
40
|
-
|
|
41
|
-
type FirebaseAppContextValue = {
|
|
42
|
-
app: FirebaseApp;
|
|
43
|
-
analytics?: Analytics;
|
|
44
|
-
performance?: FirebasePerformance;
|
|
45
|
-
remoteConfig?: RemoteConfig;
|
|
46
|
-
storage?: FirebaseStorage;
|
|
47
|
-
auth?: Auth;
|
|
48
|
-
database?: Database;
|
|
49
|
-
firestore?: Firestore;
|
|
50
|
-
};
|
|
51
|
-
declare const FirebaseAppContext: React.Context<FirebaseAppContextValue | undefined>;
|
|
52
|
-
|
|
53
|
-
export { FirebaseAppContext, type FirebaseAppContextValue, FirebaseAppProvider, type FirebaseAppProviderProps, useAnalytics, useAuth, useDatabase, useFirebaseApp, useFirestore, usePerformance, useRemoteConfig, useStorage };
|
package/dist/index.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React2 = require('react');
|
|
4
|
-
var firebaseCore = require('@nardole/firebase-core');
|
|
5
|
-
|
|
6
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
9
|
-
|
|
10
|
-
// src/hooks/index.ts
|
|
11
|
-
var FirebaseAppContext = React2__default.default.createContext(void 0);
|
|
12
|
-
|
|
13
|
-
// src/hooks/index.ts
|
|
14
|
-
function useFirebaseApp() {
|
|
15
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
16
|
-
if (!value || value.app === void 0) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
"Firebase app isn't found, did you forget to wrap your app in <FirebaseAppProvider>"
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
return value.app;
|
|
22
|
-
}
|
|
23
|
-
function useAnalytics() {
|
|
24
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
25
|
-
if (!value || value.analytics === void 0) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"Firebase analytics isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return value.analytics;
|
|
31
|
-
}
|
|
32
|
-
function usePerformance() {
|
|
33
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
34
|
-
if (!value || value.performance === void 0) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
"Firebase performance isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return value.performance;
|
|
40
|
-
}
|
|
41
|
-
function useRemoteConfig() {
|
|
42
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
43
|
-
if (!value || value.remoteConfig === void 0) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
"Firebase remote config isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return value.remoteConfig;
|
|
49
|
-
}
|
|
50
|
-
function useStorage() {
|
|
51
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
52
|
-
if (!value || value.storage === void 0) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
"Firebase storage isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return value.storage;
|
|
58
|
-
}
|
|
59
|
-
function useAuth() {
|
|
60
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
61
|
-
if (!value || value.auth === void 0) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
"Firebase auth isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return value.auth;
|
|
67
|
-
}
|
|
68
|
-
function useDatabase() {
|
|
69
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
70
|
-
if (!value || value.database === void 0) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
"Firebase database isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return value.database;
|
|
76
|
-
}
|
|
77
|
-
function useFirestore() {
|
|
78
|
-
const value = React2.useContext(FirebaseAppContext);
|
|
79
|
-
if (!value || value.firestore === void 0) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
"Firebase firestore isn't found, did you forget to enable it in <FirebaseAppProvider>"
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return value.firestore;
|
|
85
|
-
}
|
|
86
|
-
function FirebaseAppProvider({
|
|
87
|
-
options,
|
|
88
|
-
name,
|
|
89
|
-
enableAnalytics,
|
|
90
|
-
enablePerformance,
|
|
91
|
-
enableRemoteConfig,
|
|
92
|
-
enableStorage,
|
|
93
|
-
enableAuth,
|
|
94
|
-
enableDatabase,
|
|
95
|
-
enableFirestore,
|
|
96
|
-
children
|
|
97
|
-
}) {
|
|
98
|
-
const optionsRef = React2__default.default.useRef(void 0);
|
|
99
|
-
const nameRef = React2__default.default.useRef(void 0);
|
|
100
|
-
const value = React2__default.default.useMemo(() => {
|
|
101
|
-
if (optionsRef.current !== options || nameRef.current !== name) {
|
|
102
|
-
firebaseCore.firebaseService.init(options, name, true);
|
|
103
|
-
}
|
|
104
|
-
optionsRef.current = options;
|
|
105
|
-
nameRef.current = name;
|
|
106
|
-
return {
|
|
107
|
-
app: firebaseCore.firebaseService.app,
|
|
108
|
-
analytics: enableAnalytics ? firebaseCore.firebaseService.analytics : void 0,
|
|
109
|
-
performance: enablePerformance ? firebaseCore.firebaseService.performance : void 0,
|
|
110
|
-
remoteConfig: enableRemoteConfig ? firebaseCore.firebaseService.remoteConfig : void 0,
|
|
111
|
-
storage: enableStorage ? firebaseCore.firebaseService.storage : void 0,
|
|
112
|
-
auth: enableAuth ? firebaseCore.firebaseService.auth : void 0,
|
|
113
|
-
database: enableDatabase ? firebaseCore.firebaseService.database : void 0,
|
|
114
|
-
firestore: enableFirestore ? firebaseCore.firebaseService.firestore : void 0
|
|
115
|
-
};
|
|
116
|
-
}, [options, name]);
|
|
117
|
-
return /* @__PURE__ */ React2__default.default.createElement(FirebaseAppContext.Provider, { value }, children);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
exports.FirebaseAppContext = FirebaseAppContext;
|
|
121
|
-
exports.FirebaseAppProvider = FirebaseAppProvider;
|
|
122
|
-
exports.useAnalytics = useAnalytics;
|
|
123
|
-
exports.useAuth = useAuth;
|
|
124
|
-
exports.useDatabase = useDatabase;
|
|
125
|
-
exports.useFirebaseApp = useFirebaseApp;
|
|
126
|
-
exports.useFirestore = useFirestore;
|
|
127
|
-
exports.usePerformance = usePerformance;
|
|
128
|
-
exports.useRemoteConfig = useRemoteConfig;
|
|
129
|
-
exports.useStorage = useStorage;
|
|
130
|
-
//# sourceMappingURL=index.js.map
|
|
131
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/index.ts","../src/hooks/index.ts","../src/provider/index.tsx"],"names":["React","useContext","firebaseService"],"mappings":";;;;;;;;;;AAqBO,IAAM,kBAAA,GAAqBA,uBAAA,CAAM,aAAA,CAEtC,MAAS;;;ACpBJ,SAAS,cAAA,GAAiB;AAC/B,EAAA,MAAM,KAAA,GAAQC,kBAAW,kBAAkB,CAAA;AAE3C,EAAA,IAAI,CAAC,KAAA,IAAS,KAAA,CAAM,GAAA,KAAQ,MAAA,EAAW;AACrC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA,CAAM,GAAA;AACf;AAEO,SAAS,YAAA,GAAe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A,OAAO;AAAA,MACL,KAAKA,4BAAA,CAAgB,GAAA;AAAA,MACrB,SAAA,EAAW,eAAA,GAAkBA,4BAAA,CAAgB,SAAA,GAAY,MAAA;AAAA,MACzD,WAAA,EAAa,iBAAA,GAAoBA,4BAAA,CAAgB,WAAA,GAAc,MAAA;AAAA,MAC/D,YAAA,EAAc,kBAAA,GACVA,4BAAA,CAAgB,YAAA,GAChB,MAAA;AAAA,MACJ,OAAA,EAAS,aAAA,GAAgBA,4BAAA,CAAgB,OAAA,GAAU,MAAA;AAAA,MACnD,IAAA,EAAM,UAAA,GAAaA,4BAAA,CAAgB,IAAA,GAAO,MAAA;AAAA,MAC1C,QAAA,EAAU,cAAA,GAAiBA,4BAAA,CAAgB,QAAA,GAAW,MAAA;AAAA,MACtD,SAAA,EAAW,eAAA,GAAkBA,4BAAA,CAAgB,SAAA,GAAY;AAAA,KAC3D;AAAA,EACF,CAAA,EAAG,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA;AAElB,EAAA,uBACEF,uBAAAA,CAAA,aAAA,CAAC,mBAAmB,QAAA,EAAnB,EAA4B,SAC1B,QACH,CAAA;AAEJ","file":"index.js","sourcesContent":["import React from \"react\";\nimport { FirebaseApp } from \"firebase/app\";\nimport { Analytics } from \"firebase/analytics\";\nimport { FirebasePerformance } from \"firebase/performance\";\nimport { RemoteConfig } from \"firebase/remote-config\";\nimport { FirebaseStorage } from \"firebase/storage\";\nimport { Auth } from \"firebase/auth\";\nimport { Database } from \"firebase/database\";\nimport { Firestore } from \"firebase/firestore\";\n\nexport type FirebaseAppContextValue = {\n app: FirebaseApp;\n analytics?: Analytics;\n performance?: FirebasePerformance;\n remoteConfig?: RemoteConfig;\n storage?: FirebaseStorage;\n auth?: Auth;\n database?: Database;\n firestore?: Firestore;\n};\n\nexport const FirebaseAppContext = React.createContext<\n FirebaseAppContextValue | undefined\n>(undefined);\n","import { useContext } from \"react\";\nimport { FirebaseAppContext } from \"@nardole/firebase-react/context\";\n\nexport function useFirebaseApp() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.app === undefined) {\n throw new Error(\n \"Firebase app isn't found, did you forget to wrap your app in <FirebaseAppProvider>\",\n );\n }\n\n return value.app;\n}\n\nexport function useAnalytics() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.analytics === undefined) {\n throw new Error(\n \"Firebase analytics isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.analytics;\n}\n\nexport function usePerformance() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.performance === undefined) {\n throw new Error(\n \"Firebase performance isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.performance;\n}\n\nexport function useRemoteConfig() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.remoteConfig === undefined) {\n throw new Error(\n \"Firebase remote config isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.remoteConfig;\n}\n\nexport function useStorage() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.storage === undefined) {\n throw new Error(\n \"Firebase storage isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.storage;\n}\n\nexport function useAuth() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.auth === undefined) {\n throw new Error(\n \"Firebase auth isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.auth;\n}\n\nexport function useDatabase() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.database === undefined) {\n throw new Error(\n \"Firebase database isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.database;\n}\n\nexport function useFirestore() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.firestore === undefined) {\n throw new Error(\n \"Firebase firestore isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.firestore;\n}\n","import React from \"react\";\nimport { FirebaseOptions } from \"firebase/app\";\nimport {\n FirebaseAppContext,\n FirebaseAppContextValue,\n} from \"@nardole/firebase-react/context\";\nimport { firebaseService } from \"@nardole/firebase-core\";\n\nexport type FirebaseAppProviderProps = React.PropsWithChildren<{\n options: FirebaseOptions;\n name?: string;\n\n enableAnalytics?: boolean;\n enablePerformance?: boolean;\n enableRemoteConfig?: boolean;\n enableStorage?: boolean;\n enableAuth?: boolean;\n enableDatabase?: boolean;\n enableFirestore?: boolean;\n}>;\n\nexport function FirebaseAppProvider({\n options,\n name,\n enableAnalytics,\n enablePerformance,\n enableRemoteConfig,\n enableStorage,\n enableAuth,\n enableDatabase,\n enableFirestore,\n children,\n}: FirebaseAppProviderProps) {\n const optionsRef = React.useRef<FirebaseOptions | undefined>(undefined);\n const nameRef = React.useRef<string | undefined>(undefined);\n\n const value: FirebaseAppContextValue = React.useMemo(() => {\n if (optionsRef.current !== options || nameRef.current !== name) {\n firebaseService.init(options, name, true);\n }\n\n optionsRef.current = options;\n nameRef.current = name;\n\n return {\n app: firebaseService.app,\n analytics: enableAnalytics ? firebaseService.analytics : undefined,\n performance: enablePerformance ? firebaseService.performance : undefined,\n remoteConfig: enableRemoteConfig\n ? firebaseService.remoteConfig\n : undefined,\n storage: enableStorage ? firebaseService.storage : undefined,\n auth: enableAuth ? firebaseService.auth : undefined,\n database: enableDatabase ? firebaseService.database : undefined,\n firestore: enableFirestore ? firebaseService.firestore : undefined,\n };\n }, [options, name]);\n\n return (\n <FirebaseAppContext.Provider value={value}>\n {children}\n </FirebaseAppContext.Provider>\n );\n}\n"]}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/index.ts","../src/hooks/index.ts","../src/provider/index.tsx"],"names":["React"],"mappings":";;;;AAqBO,IAAM,kBAAA,GAAqBA,MAAA,CAAM,aAAA,CAEtC,MAAS;;;ACpBJ,SAAS,cAAA,GAAiB;AAC/B,EAAA,MAAM,KAAA,GAAQ,WAAW,kBAAkB,CAAA;AAE3C,EAAA,IAAI,CAAC,KAAA,IAAS,KAAA,CAAM,GAAA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IAAA,EAAM,IAAI,CAAA;AAAA,IAC1C;AAEA,IAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AACrB,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAElB,IAAA,OAAO;AAAA,MACL,KAAK,eAAA,CAAgB,GAAA;AAAA,MACrB,SAAA,EAAW,eAAA,GAAkB,eAAA,CAAgB,SAAA,GAAY,MAAA;AAAA,MACzD,WAAA,EAAa,iBAAA,GAAoB,eAAA,CAAgB,WAAA,GAAc,MAAA;AAAA,MAC/D,YAAA,EAAc,kBAAA,GACV,eAAA,CAAgB,YAAA,GAChB,MAAA;AAAA,MACJ,OAAA,EAAS,aAAA,GAAgB,eAAA,CAAgB,OAAA,GAAU,MAAA;AAAA,MACnD,IAAA,EAAM,UAAA,GAAa,eAAA,CAAgB,IAAA,GAAO,MAAA;AAAA,MAC1C,QAAA,EAAU,cAAA,GAAiB,eAAA,CAAgB,QAAA,GAAW,MAAA;AAAA,MACtD,SAAA,EAAW,eAAA,GAAkB,eAAA,CAAgB,SAAA,GAAY;AAAA,KAC3D;AAAA,EACF,CAAA,EAAG,CAAC,OAAA,EAAS,IAAI,CAAC,CAAA;AAElB,EAAA,uBACEA,MAAAA,CAAA,aAAA,CAAC,mBAAmB,QAAA,EAAnB,EAA4B,SAC1B,QACH,CAAA;AAEJ","file":"index.mjs","sourcesContent":["import React from \"react\";\nimport { FirebaseApp } from \"firebase/app\";\nimport { Analytics } from \"firebase/analytics\";\nimport { FirebasePerformance } from \"firebase/performance\";\nimport { RemoteConfig } from \"firebase/remote-config\";\nimport { FirebaseStorage } from \"firebase/storage\";\nimport { Auth } from \"firebase/auth\";\nimport { Database } from \"firebase/database\";\nimport { Firestore } from \"firebase/firestore\";\n\nexport type FirebaseAppContextValue = {\n app: FirebaseApp;\n analytics?: Analytics;\n performance?: FirebasePerformance;\n remoteConfig?: RemoteConfig;\n storage?: FirebaseStorage;\n auth?: Auth;\n database?: Database;\n firestore?: Firestore;\n};\n\nexport const FirebaseAppContext = React.createContext<\n FirebaseAppContextValue | undefined\n>(undefined);\n","import { useContext } from \"react\";\nimport { FirebaseAppContext } from \"@nardole/firebase-react/context\";\n\nexport function useFirebaseApp() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.app === undefined) {\n throw new Error(\n \"Firebase app isn't found, did you forget to wrap your app in <FirebaseAppProvider>\",\n );\n }\n\n return value.app;\n}\n\nexport function useAnalytics() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.analytics === undefined) {\n throw new Error(\n \"Firebase analytics isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.analytics;\n}\n\nexport function usePerformance() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.performance === undefined) {\n throw new Error(\n \"Firebase performance isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.performance;\n}\n\nexport function useRemoteConfig() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.remoteConfig === undefined) {\n throw new Error(\n \"Firebase remote config isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.remoteConfig;\n}\n\nexport function useStorage() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.storage === undefined) {\n throw new Error(\n \"Firebase storage isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.storage;\n}\n\nexport function useAuth() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.auth === undefined) {\n throw new Error(\n \"Firebase auth isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.auth;\n}\n\nexport function useDatabase() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.database === undefined) {\n throw new Error(\n \"Firebase database isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.database;\n}\n\nexport function useFirestore() {\n const value = useContext(FirebaseAppContext);\n\n if (!value || value.firestore === undefined) {\n throw new Error(\n \"Firebase firestore isn't found, did you forget to enable it in <FirebaseAppProvider>\",\n );\n }\n\n return value.firestore;\n}\n","import React from \"react\";\nimport { FirebaseOptions } from \"firebase/app\";\nimport {\n FirebaseAppContext,\n FirebaseAppContextValue,\n} from \"@nardole/firebase-react/context\";\nimport { firebaseService } from \"@nardole/firebase-core\";\n\nexport type FirebaseAppProviderProps = React.PropsWithChildren<{\n options: FirebaseOptions;\n name?: string;\n\n enableAnalytics?: boolean;\n enablePerformance?: boolean;\n enableRemoteConfig?: boolean;\n enableStorage?: boolean;\n enableAuth?: boolean;\n enableDatabase?: boolean;\n enableFirestore?: boolean;\n}>;\n\nexport function FirebaseAppProvider({\n options,\n name,\n enableAnalytics,\n enablePerformance,\n enableRemoteConfig,\n enableStorage,\n enableAuth,\n enableDatabase,\n enableFirestore,\n children,\n}: FirebaseAppProviderProps) {\n const optionsRef = React.useRef<FirebaseOptions | undefined>(undefined);\n const nameRef = React.useRef<string | undefined>(undefined);\n\n const value: FirebaseAppContextValue = React.useMemo(() => {\n if (optionsRef.current !== options || nameRef.current !== name) {\n firebaseService.init(options, name, true);\n }\n\n optionsRef.current = options;\n nameRef.current = name;\n\n return {\n app: firebaseService.app,\n analytics: enableAnalytics ? firebaseService.analytics : undefined,\n performance: enablePerformance ? firebaseService.performance : undefined,\n remoteConfig: enableRemoteConfig\n ? firebaseService.remoteConfig\n : undefined,\n storage: enableStorage ? firebaseService.storage : undefined,\n auth: enableAuth ? firebaseService.auth : undefined,\n database: enableDatabase ? firebaseService.database : undefined,\n firestore: enableFirestore ? firebaseService.firestore : undefined,\n };\n }, [options, name]);\n\n return (\n <FirebaseAppContext.Provider value={value}>\n {children}\n </FirebaseAppContext.Provider>\n );\n}\n"]}
|