Atomic Layout
  • Introduction
  • Motivation
  • Resources
  • FAQ
    • Comparison with styled-system
  • Getting started
    • Installation
    • First composition
    • Responsive composition
    • Nested composition
  • Fundamentals
    • Breakpoints
    • Prop aliases
    • Responsive props
  • API
    • Layout
      • configure()
    • Components
      • Box
      • Composition
      • Only
      • Visible
    • Hooks
      • useMediaQuery
      • useResponsiveQuery
      • useViewportChange
      • useBreakpointChange
      • useResponsiveValue
      • useResponsiveProps
    • Utilities
      • query
      • makeResponsive
  • Recipes
    • Semantics
    • Namespaces
    • Iterative areas
    • Responsive layout
    • Explicit media query
Powered by GitBook
On this page
  • Specification
  • Definition
  • Example
  1. API
  2. Hooks

useBreakpointChange

PrevioususeViewportChangeNextuseResponsiveValue

Last updated 5 years ago

Specification

Executes a given callback function whenever a breakpoint changes. Provides a breakpoint name that matches the current viewport as the first argument.

Breakpoint changes are based on , and are also debounced.

Definition

type useBreakpointChange = (
  callback: (breakpointName: string) => void,
  debounceDuration?: number,
)

Example

import React, { useState } from 'react'
import { useBreakpointChange } from 'atomic-layout'

export const Component = () => {
  const [currentBreakpoint, setCurrentBreakpoint] = useState()

  useBreakpointChange((breakpointName) => {
    setCurrentBreakpoint(breakpointName)
  })
  
  return <p>Current breakpoint: {currentBreakpoint}</p>
})
useViewportChange