import React, { useEffect, useState } from "react";
import "./styles.css";
export default function App() {
const [videoDevicesList, setVideoDevices] = useState([]);
useEffect(() => {
// navigator.mediaDevices.enumerateDevices().then(gotDevices)
if (true) {
(async () => {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoInput = devices.filter(
(device) => device.kind === "videoinput"
);
setVideoDevices(videoInput);
})();
}
}, []);
return (
<div className="App">
{JSON.stringify(videoDevicesList)}
<h1>Loop</h1>
{videoDevicesList.forEach((device) => (
<div key={device.groupId}>{device.groupId}</div>
))}
</div>
);
}
I have this code. {JSON.stringify(videoDevicesList)} prints an array in the UI.
Also typeof videoDevicesList retruns object.
And I want to loop through the array and print the groupId.
But this doesn't work.
How do I fix this error?
Any help!
Thanks in advance. =)