Use-media-stream 2.0.0 – React hook for getUserMedia that cleans up after itself

kothariji1 pts0 comments

use-media-stream | use-media-streamSkip to contentuse-media-stream<br>A React hook for getUserMedia that cleans up after itself. Cameras, microphones, device switching and track muting — without the lifecycle bugs.

Get startedLive demoGitHub

Terminal windownpm install use-media-stream

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

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

Cleans up on unmount<br>Tracks are released when your component goes away. No lingering camera light, no useEffect<br>teardown to remember.

Mute without dropping the device<br>Muting toggles track.enabled, so unmuting is instant and the browser doesn’t prompt again.

Device switching built in<br>Devices split by kind, with the live track’s real settings — the resolution you got, not the<br>one you asked for.

Server-safe<br>Renders in Next.js and Remix without a typeof window dance. isSupported is simply false.

Zero dependencies<br>Nothing in your tree but the hook. ESM and CommonJS, fully typed, published with provenance.

Tested where it matters<br>100% branch coverage, with the lifecycle leaks pinned by regression tests.

Next steps<br>Section titled “Next steps”

InstallationInstall it, and what changed if you're coming from v1.<br>Quick startA working camera component in about fifteen lines.<br>Live demoEvery function, wired to a real camera, in your browser.

stream media hook device track camera

Related Articles