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
  • Examples
  1. API
  2. Hooks

useResponsiveQuery

Specification

React hook that accepts a responsive props interface and resolves to a boolean verdict, indicating whether current viewport matches the given range.

Definition

type UseResponsiveQuery = (
  params: UseResponsiveQueryParams,
  initialMatches: boolean
) => boolean


interface UseResponsiveQueryParams {
  for: BreakpointRef
  from: BreakpointRef
  to: BreakpointRef
  except: boolean
}

type BreakpointRef = MediaQuery | string

Examples

import { useResponsiveQuery } from 'atomic-layout'

export const UsageExample = () => {
  const inScreenRange = useResponsiveQuery({ from: 'sm', to: 'lg' })
  
  return (
    <div>
      {inScreenRange && <h1>Component</h1>}
    </div>
  )
}
PrevioususeMediaQueryNextuseViewportChange

Last updated 5 years ago