I have a weird situation. I have the following code which is not working.
const [result, setResult] = useState(props.fileNamesStatus.map((file, i) => {
return {
key: file.fileStatus
}
}));
Strangely though, it works sometimes and sometimes it does not. I have used it in the JSX as follows:
I get the error
Cannot read property 'key' of undefined
<ul className="in">
{props.fileNamesStatus.map((file, i) => {
console.log(result[i].key) /// Cannot read property 'key' of undefined
})}
</ul>