I am trying to display multiple video streams by appending video to an array and using .map to render videos. If I use the following approach I get the error "Unhandled Rejection (TypeError): Cannot set property 'srcObject' of null". How do I append and display multiple video streams in React?
import React, {useState, useEffect} from 'react';
import {View} from 'react-native';
function createVideo(stream){
const localVideo = React.createRef();
localVideo.current.srcObject = stream;
return(
<View>
<video style = {{height: 100, width: 100}} ref = {localVideo} autoPlay />
</View>
)
}
const Test = () =>{
const videos = [];
navigator.mediaDevices.getUserMedia({video: true}).then(stream => {
videos.push(createVideo(stream));
})
return(
<View>
{
videos.map(data => data)
}
</View>
)
}
export default Test;