Open
Description
Describe the bug
You can't specify the largest breakpoint as the defaultIndex
in useBreakpointIndex
when using ssr.
To Reproduce
Steps to reproduce the behavior:
- Create a new app using the base theme
- Import
@theme-ui/match-media
- Create a component that uses
useBreakpointIndex
, setting thedefaultIndex
to 3 - Render the component using ssr
Expected behavior
useBreakpointIndex
by default returns 0-3, because it gets the length of how many breakpoints it matches (of which there are three by default). I expect to be able to pass the max breakpoint index (3) as the default.
Additional context
There's a check for if the defaultIndex
passed is < 0 || > breakpoints.length - 1
, but really you're not passing in the actual breakpoint index you want, but the number of breakpoints the screen currently matches:
return breakpoints.filter(
breakpoint =>
window.matchMedia(`screen and (min-width: ${breakpoint})`).matches
).length
Which produces 0-3.
Activity