develop
useBreakpointsConfig
A custom breakpoints configurator.
This custom hook is built upon useBreakpoints() and returns the provided configuration depending on the current breakpoint match. It responds to window resizing and is built to work in server-side rendering (SSR) applications.
Usage
import { useBreakpointsConfig } from "@wonderflow/react-components";
type Config = {
direction: "row" | "column";
hPadding: "8" | "16" | "32";
vPadding: "8" | "16";
}
export default () {
const { matches, value } = useBreakpointsConfig<Config>({
md: { direction: "row", hPadding: "16", vPadding: "8" },
lg: { direction: "row", hPadding: "32", vPadding: "16" },
xl: { direction: "row", hPadding: "32", vPadding: "16" },
fallback: { direction: "column", hPadding: "8", vPadding: "16" },
});
return (
<Stack direction={value.direction} hPadding={value.hPadding} vPadding={value.vPadding}>
<p>{`Key: ${matches}`}</p>
<p>{`Value: ${JSON.stringify(value)}`}</p>
</Stack>)
}API Reference
PROPERTY
TYPE
DEFAULT
config*BreakpointsConfig<T>targetMutableRefObject<HTMLElement | null>The window objectsettingsBreakpointsSettingsSystem BreakpointsReturn value
VALUE
TYPE
DESCRIPTION
value<T>The value configured for any breakpoint match or the fallback value
breakpointsBreakepointsValueA key/value pair object with boolean for every breakpoint
matchesBreakpointsNamexs | sm | md | lg | xl
sizenumberThe window or target width