Skip to content

Commit abac015

Browse files
committed
fix(react): Correctly throw when no context is found (bb-63)
1 parent fdaa47b commit abac015

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

packages/react/src/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useStore } from "@nanostores/react";
1919
import { type PolicyProps, PolicyProvider } from "~/components/policies";
2020
import { createContext } from "react";
2121

22-
export const FirebaseUIContext = createContext<FirebaseUI>({} as FirebaseUI);
22+
export const FirebaseUIContext = createContext<FirebaseUI>(null as unknown as FirebaseUI);
2323

2424
export type FirebaseUIProviderProps = {
2525
children: React.ReactNode;

packages/react/src/hooks.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ describe("useUI", () => {
6363
expect(result.current).toEqual(mockUI.get());
6464
});
6565

66-
// TODO(ehesp): This test is not working as expected.
67-
it.skip("throws an error if no context is found", () => {
66+
it("throws an error if no context is found", () => {
6867
expect(() => {
6968
renderHook(() => useUI());
70-
}).toThrow("No FirebaseUI context found. Your application must be wrapped in a <FirebaseUIProvider> component.");
69+
}).toThrow();
7170
});
7271

7372
it("returns updated values when nanostore state changes via setState", () => {

packages/react/src/hooks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ export function useUI() {
4040

4141
if (!ui) {
4242
throw new Error(
43-
"No FirebaseUI context found. Your application must be wrapped in a <FirebaseUIProvider> component."
43+
`No FirebaseUI context found. Your application must be wrapped in a FirebaseUIProvider:
44+
45+
const ui = initializeUI(...);
46+
47+
<FirebaseUIProvider ui={ui}>
48+
<App />
49+
</FirebaseUIProvider>
50+
`
4451
);
4552
}
4653

0 commit comments

Comments
 (0)