Skip to content

use-media-stream

A React hook for getUserMedia that cleans up after itself. Cameras, microphones, device switching and track muting — without the lifecycle bugs.
Terminal window
npm install use-media-stream

Getting a camera stream is one line. Getting it to stop is where the bugs are — a component unmounts and the recording light stays on, a device list leaves an orphaned stream open, a track goes silent and your UI never notices.

This hook owns that lifecycle so you don’t have to.

Cleans up on unmount

Tracks are released when your component goes away. No lingering camera light, no useEffect teardown to remember.

Mute without dropping the device

Muting toggles track.enabled, so unmuting is instant and the browser doesn’t prompt again.

Device switching built in

Devices split by kind, with the live track’s real settings — the resolution you got, not the one you asked for.

Server-safe

Renders in Next.js and Remix without a typeof window dance. isSupported is simply false.

Zero dependencies

Nothing in your tree but the hook. ESM and CommonJS, fully typed, published with provenance.

Tested where it matters

100% branch coverage, with the lifecycle leaks pinned by regression tests.