[useBreakpoint/useBreakpointValue] API partially broken
See original GitHub issueAs reported on Discord, the return value of useBreakpoint
and useBreakpointValue
is undefined
if no matching breakpoint is currently active; it should fallback to base
if given.
Also, the passed argument must currently match array indices:
{base: 'column', 0: 'column', 1: 'row', 2: 'row', 3: 'row'}
instead of, following the docs,
{base: 'column', sm: 'column', md: 'row', lg: 'row', lg: 'row'}
.
It’s also broken in the docs; variant
is always undefined
according to the devtools:
https://codesandbox.io/s/distracted-bird-3ifkq?file=/src/App.tsx
Expected Behavior API works as expected.
Suggested solution(s)
Investigate what goes wrong here.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
useBreakpointValue - Chakra UI
React hook for getting the value for the current breakpoint from the provided responsive values object.
Read more >Having trouble to use [...Array(stateValue)] in React. Not sure if ...
It seems the styles object are breaking the breakpoints you've set on ... const breakpointValue = useBreakpointValue({ sm: 0, md: 1, lg: 2, ......
Read more >@chakra-ui/react UnorderedList JavaScript Examples
You may check out the related API usage on the sidebar. ... <ListItem>If there is an error the import process will continue resulting...
Read more >useBreakpointValue - NativeBase
useBreakpointValue returns the value for the current breakpoint based on the provided responsive values object. It is also responsive to window resizing and ......
Read more >React Hook 'useBreakpointValue' cannot be called inside a ...
When building components with Chakra UI, you may be trying to create mobile responsive layouts. You may have found the useBreakpointValue in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nassimbenkirane See #1467
https://github.com/chakra-ui/chakra-ui/blob/3352c105f99c4264d47ee9dc9787b8d6d1334110/packages/media-query/src/create-media-query.ts#L14
In here the descending order sorted breakpoint keys (
sorted
) used to be['xl', 'lg', 'md', 'sm', 'base']
when the breakpoint was defined as an object.Since then the theme breakpoint definition was changed to an array with additional keys, here : https://github.com/chakra-ui/chakra-ui/commit/5677f1a4501e4c862c541fdfcd43fcd49c6f4e84, so now the descending order breakpoint keys look like this
['3', 'xl', '2' ,'lg', '1', 'md', '0', 'base']
So I would either filter out the numerical values to produce the same values as before
Or adapt the
next
computation so it gets the actual next values :First case would yield :
Second case would yield :
but then it would probably not be enough for useBreakpoint to work, since it tries to find the first breakpoint that matches https://github.com/chakra-ui/chakra-ui/blob/9ed9d3aea959f38198b1ba0d48c24686630aee90/packages/media-query/src/use-breakpoint.ts#L61
I would go with 1) but I don’t know if it can break things elsewhere …
P.S. I didn’t try any of the code so it might be very wrong ^^