Code is the following:
return (
<MuiThemeProvider>
<GridList>
{singleProd.map(function(product) {
// console.log(product)
let fileID;
try {
api.GetFile(product.relationships.main_image.data.id)
.then((file) => {
fileID = file.data.link.href;
console.log(fileID)
return (
<Tile name={product.name} id={product.id} link={fileID} key={product.id} />
)
})
}
catch(e){
console.log('product has no main image');
return (
<Tile name={product.name} id={product.id} link={fileID} key={product.id} />
)
}
})}
</GridList>
</MuiThemeProvider>
)
Error is: Cannot read property '_currentElement' of null
The diagnosis so far is that nothing is being returned for the .map function, because the returns are each wrapped in try catch blocks respectively.
If you add a return outside the try catch, it will succeed.
Wondering how I should format this so that each of the objects in the .map is run through the try catch. If the try succeeds, then that jsx is returned and used. If it doesn't, then the catch jsx is returned and used.
Any ideas how I might restructure the code above?
Other relevant info:
- using material UI Tiles
- using external API calls which return an array of objects, hence the map
- the tile for each object is returned and becomes part of the gridList.