|
| 1 | +import type { ExtendedResizeObserverEntry } from '@envato/react-resize-observer-hook'; |
| 2 | +import type { Breakpoints } from './Breakpoints'; |
1 | 3 | import { useRef, useState, useEffect, useMemo } from 'react'; |
2 | | -import { ExtendedResizeObserverEntry } from '@envato/react-resize-observer-hook'; |
3 | | -import { Breakpoints } from './Breakpoints'; |
4 | 4 | import { useResizeObserverEntry } from './useResizeObserverEntry'; |
5 | 5 | import { findBreakpoint } from './findBreakpoint'; |
6 | 6 |
|
@@ -28,19 +28,19 @@ export type UseBreakpointsResult = [any, any] & Matches; |
28 | 28 | const boxOptions = { |
29 | 29 | BORDER_BOX: 'border-box', // https://caniuse.com/mdn-api_resizeobserverentry_borderboxsize |
30 | 30 | CONTENT_BOX: 'content-box', // https://caniuse.com/mdn-api_resizeobserverentry_contentboxsize |
31 | | - DEVICE_PIXEL_CONTENT_BOX: 'device-pixel-content-box' // https://github.com/w3c/csswg-drafts/pull/4476 |
| 31 | + DEVICE_PIXEL_CONTENT_BOX: 'device-pixel-content-box' // https://caniuse.com/mdn-api_resizeobserverentry_devicepixelcontentboxsize |
32 | 32 | }; |
33 | 33 |
|
34 | 34 | /** |
35 | | - * See API Docs: {@linkcode https://github.com/envato/react-breakpoints/blob/master/docs/api.md#usebreakpoints|useBreakpoints} |
| 35 | + * See API Docs: {@linkcode https://github.com/envato/react-breakpoints/blob/main/docs/api.md#usebreakpoints useBreakpoints} |
36 | 36 | * |
37 | 37 | * Pass in an options object with at least one of the following properties: |
38 | 38 | * - `widths`: objects with width breakpoints as keys and anything as their values; |
39 | 39 | * - `heights`: objects with height breakpoints as keys and anything as their values. |
40 | 40 | * |
41 | 41 | * You may also pass the following additional optional properties: |
42 | 42 | * - `box`: the box to measure on the observed element, one of `'border-box' | 'content-box' | 'device-pixel-content-box'`; |
43 | | - * - `fragment`: index of {@link https://github.com/w3c/csswg-drafts/pull/4529|fragment} of the observed element to measure (default `0`). |
| 43 | + * - `fragment`: index of {@link https://github.com/w3c/csswg-drafts/pull/4529 fragment} of the observed element to measure (default `0`). |
44 | 44 | * |
45 | 45 | * Optionally pass in a `ResizeObserverEntry` as the second argument to override fetching one from context. |
46 | 46 | * |
@@ -106,11 +106,7 @@ export const useBreakpoints = ( |
106 | 106 | break; |
107 | 107 |
|
108 | 108 | case boxOptions.DEVICE_PIXEL_CONTENT_BOX: |
109 | | - if (typeof resizeObserverEntry.devicePixelContentBoxSize !== 'undefined') { |
110 | | - observedBoxSize = resizeObserverEntry.devicePixelContentBoxSize[fragment]; |
111 | | - } else { |
112 | | - throw Error('resizeObserverEntry does not contain devicePixelContentBoxSize.'); |
113 | | - } |
| 109 | + observedBoxSize = resizeObserverEntry.devicePixelContentBoxSize[fragment]; |
114 | 110 | break; |
115 | 111 |
|
116 | 112 | default: |
|
0 commit comments