Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
¿Hay alguna manera de verificar si el archivo es una imagen o un video al mapear sobre una matriz?

Estoy trabajando en mi Portafolio, y actualmente estoy mapeando una matriz para crear una lista de proyectos que contienen múltiples imágenes como un componente Slider (Swiper).

Ahora lo que necesito sería la posibilidad de incluir también videos en lugar de una imagen. Entonces, creo que podría necesitar algo que verifique si el archivo pasado es una imagen o un video y luego seleccione la etiqueta html adecuada (/). ¿Hay una manera simple de lograr esto?

Ejemplo de mi código (reducido a partes relevantes):

Mapeo sobre un Componente de Proyecto para generar proyectos:

 {allData.map((project) => ( <Project id={project.id} text={project.title} vids={project.videos} imgs={project.images} description={project.info} /> ))}

Pasando los datos al Componente del Proyecto:

 const Project = ({ text, vids, imgs, description }) => { {imgs.map(e => ( <SwiperSlide> <div className="image-container"> <img className="image-center" src={e} /> </div> </SwiperSlide> ))} {vids.map(video => ( <SwiperSlide> <video src={video} /> </SwiperSlide> ))}

Cómo se ve la matriz:

 import img1 from './img/1.jpg'; import img2 from './img/2.jpg'; import img3 from './img/3.jpg'; import video1 from './video/1.mp4'; const allData = [ { id:1, images: [img1, img2, img3] title: 'Example-title', }, { id:2, images: [img3] videos: [video1] title: 'Example-title', } export default allData

¿Puede alguien por favor me ayude con esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba esto:

 const isImage = ['.gif','.jpg','.jpeg','.png']; //you can add more const isVideo =['.mpg', '.mp2', '.mpeg', '.mpe', '.mpv', '.mp4'] // you can add more extention //merge image and video in single array const Project = ({ text, files, description }) => { {files.map(e => ( <SwiperSlide> <div className="image-container"> { isImage?.includes(e) && <img className="image-center" src={e} /> } {isVideo?.includes(e) && <video src={e} /> } </div> </SwiperSlide> ))} }

Gracias.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!