useDeviceKind

@sushindustries/ui

Which machine the stylesheet is currently drawing, as a value. Null until mounted, on purpose.

5 min read
View as MarkdownEdit on GitHub

Install commands are on Home, attached from the registry - they are not written here, because a second copy is a copy that goes stale. This tab starts after the install worked.

Use it

import { useDeviceKind } from "@sushindustries/ui";

export function DeviceReadout() {
	const kind = useDeviceKind(); // "phone" | "tablet" | "laptop" | null

	return <p>{kind ?? "not mounted yet"}</p>;
}
tsx

What you should see

"not mounted yet" for the first render - including the one the server sent - then the real machine name as soon as the effect runs and a media query matches. Resize the window across a breakpoint and the value updates without a reload.

If nothing happens

The value stays null forever only when window.matchMedia is unavailable, which in practice means a non-browser environment. In a normal browser the usual mistake is expecting a value on the very first render - it is null there by contract, on the server and on the client, so code that reads it before the first effect has to handle that case rather than treat it as a bug.

Used byDeviceDeviceA phone, a tablet or a laptop in CSS 3D, chosen by the stylesheet rather than by JavaScript, whose screen is a real scroll container with real controls in it.@sushindustries/ui · layoutShowcaseShowcaseA component in a real iframe at every width it has to survive, side by side, with its source and install commands.@sushindustries/ui · docs