react-use-user-media
React hook for accessing user media.
Installation
Using npm:
$ npm install --save react-use-user-media
Using yarn:
$ yarn add react-use-user-media
Since this module uses React Hooks, to try this out you'll need to install at least
the 16.8.0
version of react
and react-dom
:
$ yarn add react@^16.8.0 react-dom@^16.8.0
Usage
;; const constraints = video: true ; { const state stream = ; const ref = ; ; if state === 'pending' return <p>Waiting...</p>; if state === 'rejected' return <p>Error: errormessage</p>; return <video ref=ref />;}
API
: error: Error state: 'pending' | 'resolved' | 'rejected' stream: MediaStream
Receives a constraints object
to call getUserMedia
with and returns an object with the stream,
the error and the state.
Note: When the constraints
change a new media stream will be requested,
so make sure you don't create a new constraints
object on every render.
Contributing
Please feel free to submit any issues or pull requests.
License
MIT