I've got a JSON array of objects (items.[{},{},{}]) which I'm mapping as 'item', and am then rendering a JSX image from an URL stored in the property item.volumeInfo.imageLinks.thumbnail. In most cases, 'thumbnail' exists, but sometimes it doesn't (if there's no image), so first I want to check if it exists, and only try to render the image if it does.
When I try to test for undefined (if (item.volumeInfo.imageLinks.thumbnail !== undefined)), I get the error (TypeError): Cannot read property 'thumbnail' of undefined (well yeah, that's why I'm doing the test!)
So I tried using 'in', but now my code just does nothing at all, no error but no render either... any tips?
this.state.jsonArray.map(item => {
if ('thumbnail' in item) {
return <img src={item.volumeInfo.imageLinks.thumbnail} />
}
})