I have a problem in a part of the code where I get the error Warning: Each child in a list should have a unique "key" prop. , I have added the key property but having an if inside the map gives me that warning. If I delete the if and try leaving one of the components the error is not shown but if I do the if it is shown.
return(
<div className="main">
{video.map(vid => (
<>
{ vid.video !== '' ? (
<VideoPlayer id={vid.id} video={vid.video} name={vid.name} poster={vid.poster} key={vid.id} />
) : (
<ImgNoVideo id={vid.id} url={vid.url} name={vid.name} poster={vid.poster} key={vid.id} />
)}
</>
))}
</div>
);
The full version of the component can be used
Fragment
, this component accepts the propertykey
if used in this way.Shorthand version of
Fragment
:Full version of
Fragment
:demonstration:
Hope this answer is helpful.