Skip to content

Commit

Permalink
patch: Change the breakpoint context to now throw when the provider h…
Browse files Browse the repository at this point in the history
…as not been declared (#126)
  • Loading branch information
alexasselin008 authored Jan 12, 2024
1 parent f685e70 commit 20515b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-clocks-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hopper-ui/styled-system": patch
---

Modify the breakpoint context to not throw, so components can render even if no provider has been declared
9 changes: 3 additions & 6 deletions packages/styled-system/src/responsive/BreakpointContext.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { createContext, useContext } from "react";
import { isNil } from "../utils/assertion.ts";
import type { Breakpoint } from "./Breakpoints.ts";

export interface BreakpointContextType {
matchedBreakpoints: Breakpoint[];
}

export const BreakpointContext = createContext<BreakpointContextType | undefined>(undefined);
export const BreakpointContext = createContext<BreakpointContextType>({
matchedBreakpoints: []
});


export function useBreakpointContext() {
const context = useContext(BreakpointContext);

if (isNil(context)) {
throw new Error("useBreakpointContext must be used within a BreakpointProvider");
}

return context;
}

0 comments on commit 20515b9

Please sign in to comment.