Ternary statements with possible null/undefined
I am working with an object with the following shape:
images is just a string with UUIDs separated by commas. If the UUID is for a video they are prefixed with "video-".
Example:
"abc,xyz,video-abc"
I am mapping over a collection of the given shape and previewing a single image for each object, and as you've prob guessed the previewImg
decides which image to preview. ex:
So the issue arises when the previewImg
selects a video. I need a placeholder image. To solve this I thought a simple Ternary would be sufficient, ie:
This ends up always showing the false result of the ternary.
the funny thing is that if I use
it will show the placeholder image, but then it shows it also shows the placeholder img when the previewImg
was intended.
I suspect that the ?.
is doing something but I have no idea how or why1 Reply
putting this aside with a temp fix that revolves around the img being broken, and if so fallbacks to a static placeholder img