Skip to content
Myr

media.ts

This file

Path

apps/web/src/features/code/media.ts

25 lines · 708 bytes · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 1–12why, one step back
1import { useMemo, useSyncExternalStore } from "react";
23const subscribe = (query: string) => (changed: () => void) => {4 const list = globalThis.matchMedia(query);56 list.addEventListener("change", changed);78 return () => {9 list.removeEventListener("change", changed);10 };11};12

Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72

line 13why, one step back
13/** False on the server and on the first render, so the markup matches. */

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 14–20why, one step back
14export const useMedia = (query: string): boolean =>
15 useSyncExternalStore(16 useMemo(() => subscribe(query), [query]),17 () => globalThis.matchMedia(query).matches,18 () => false19 );20

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 21why, one step back
21export const COLUMNS_QUERY = "(min-width: 68.75rem)";

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 22–25why, one step back
22
23export const SPLIT_QUERY = "(min-width: 48rem)";2425export const TABLET_QUERY = "(min-width: 40rem)";