-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: Change the breakpoint context to now throw when the provider h…
…as not been declared (#126)
- Loading branch information
1 parent
f685e70
commit 20515b9
Showing
2 changed files
with
8 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |