0

Trying to conditionally render different media (audio/video) from a JSON file in react but getting errors.

Here is the code:

   {surgeryData.map(data => (
      <div>
         <Plyr
            source={
               ((type = {data.type}),
               (sources = [
                  {
                     src = {data.media}
                  }
               ]))
            }
         />
      </div>
   ))}

Whether I use = after source or : react doesn't seem to like the nested data inside the source. Any solutions?

nagendra nag
  • 1,142
  • 2
  • 15

1 Answers1

1

Per the documentation, source should be an object like this.

{surgeryData.map((data) => (
  <div>        
    <Plyr
      source={{
        type: data.type,
        sources: [
          {
            src: data.media
          }
        ]
      }}
    />
  </div>
 ))}
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34