File tree 2 files changed +7
-3
lines changed
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 35
35
"devDependencies" : {
36
36
"@types/node" : " ^14" ,
37
37
"@types/react" : " ^17" ,
38
- "@types/tailwindcss" : " ^2" ,
39
38
"eslint" : " ^7" ,
40
39
"eslint-config-kdnj" : " ^1" ,
41
40
"husky" : " ^7" ,
Original file line number Diff line number Diff line change @@ -86,7 +86,11 @@ export type CreatorReturnType = {
86
86
* export const { useBreakpoint, ... } = create({ sm: "640px", ... });
87
87
* ```
88
88
*/
89
- export function create < Screens extends { readonly [ breakpoint : string ] : string } > ( screens : Screens ) {
89
+ export function create ( screens : object | undefined ) {
90
+ if ( ! screens ) {
91
+ throw new Error ( "Failed to create breakpoint hooks, given `screens` value is invalid." ) ;
92
+ }
93
+
90
94
function useBreakpoint ( breakpoint : string , defaultValue : boolean = false ) {
91
95
const [ match , setMatch ] = React . useState ( ( ) => defaultValue ) ;
92
96
const matchRef = React . useRef ( defaultValue ) ;
@@ -95,7 +99,8 @@ export function create<Screens extends { readonly [breakpoint: string]: string }
95
99
if ( ! ( isBrowser && "matchMedia" in window ) ) return undefined ;
96
100
97
101
function track ( ) {
98
- const value = ( screens [ breakpoint ] as "" ) ?? "999999px" ;
102
+ // @ts -expect-error accessing index with uncertain `screens` type
103
+ const value = ( screens [ breakpoint ] as string ) ?? "999999px" ;
99
104
const query = window . matchMedia ( `(min-width: ${ value } )` ) ;
100
105
matchRef . current = query . matches ;
101
106
if ( matchRef . current != match ) {
You can’t perform that action at this time.
0 commit comments