Develop ultra fast with Prismane 🎉

useMediaQuery

useMediaQuery hook provides a simple way to handle media queries.

Import

import { useMediaQuery } from "@prismane/core/hooks";

Usage

function Demo() {
  const isMobile = useMediaQuery("(max-width: 768px)");

  return (
    <Text
      cl={(theme) => (theme.mode === "dark" ? ["base", 200] : ["base", 700])}
    >
      {isMobile ? "Mobile View" : "Desktop View"}
    </Text>
  );
}

API

Parameters

NameTypeDescriptionDefault
querystringThe media query that should be tracked.-

Return Value

NameTypeDescription
matchesbooleanThe boolean that shows if the current media query is true or false.