Solution 1 :

After you create a ref to the video element, you must use the video.current property to access the DOM element. Your code should look like this:

<video ref={videos}  autoPlay ></video>
   <Button onClick={() => 
    navigator.mediaDevices.getUserMedia({audio: true, video: true})
    .then((mediaStream) => {
      videos.current.srcObject = mediaStream;
      videos.current.onloadedmetadata = function(e) {
      videos.current.play();
      };
    }
    )}>Record</Button>

This should fix the problem.

Problem :

Here is the HTML code

<video ref={videos}  autoPlay ></video>

   <Button onClick={() => 
navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((mediaStream) => {

  videos.srcObject = mediaStream;
  videos.onloadedmetadata = function(e) {
    videos.play();
  };
}
)}>Record</Button>

JS

const videos = createRef(null);

Error

Unhandled Rejection (TypeError): Cannot add property srcObject, object is not extensible

 353 |    <Button onClick={() => 
  354 | navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((mediaStream) => {
  355 | 
> 356 |   videos.srcObject= mediaStream;
  357 |   videos.onloadedmetadata = function(e) {
  358 |     videos.play();
  359 |   };

Comments

Comment posted by the tutorial

You are probably looking for the DOM element,

Comment posted by Raphael Inyang

This should work, I saw the “` . current “` but I thought it was for only text inputs

Comment posted by reactjs.org/docs/refs-and-the-dom.html

@RaphaelInyang, check docs)

Comment posted by Raphael Inyang

I wasn’t at home, to confirm its credibility, I’ll mark it once I confirm it

By