develop
useBreakpoints
Current breakpoint, with a touch of flexibility.
By default, this hook returns the current breakpoint. It responds to window resizing and is built to work in server-side rendering (SSR) applications. In more detail, it provides information about the size of the window width or, optionally, the width of a target element. It also provides the ability to pass a custom breakpoints object setting upon which to map the target element.
Unlike the useResponsiveContext() hook, it returns a true value only for the breakpoint in use and does not require a context provider.
Usage
import { useBreakpoints } from "@wonderflow/react-components";
export default () {
const { breakpoints, matches, size } = useBreakpoints();
return (
<div>
<p>{`Breakpoints: ${JSON.stringify(breakpoints)}`}</p>
<p>{`Matches: ${matches}`}</p>
<p>{`Size: ${size}`}</p>
</div>)
}API Reference
PROPERTY
TYPE
DEFAULT
targetMutableRefObject<HTMLElement | null>settingsBreakpointsSettingsSystem BreakpointsReturn value
VALUE
TYPE
DESCRIPTION
breakpointsBreakepointsValueA key/value pair object with boolean for every breakpoint
matchesBreakpointsNamexs | sm | md | lg | xl
sizenumberThe window or target width