Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
How to pass local video file as a prop to ReactPlayer

I'm using react-player component for this.

I have file 1 where I'm storing some data as an array, including a local video.

import videoSample from "../assets/videos/sample-video.mov";

export const Data = {
  ProjectList: [
    {
      title: "My title",
      desc: "Some description",
      videoUrl: { videoSample },
      sourceUrl: "https:// ... ",
    },
  ],
};

File 2 takes the array and maps each item to a React component called ProjectDetail.

function MappingFunction() {
  return (
    <>
      {Data.ProjectList.map((project, index) => (
          <ProjectDetail key={index} {...project} />
      ))}
    </>
  );
}

Finally, this is file 3 which contains ProjectDetail. It takes the array item as props. videoUrl is passed to the ReactPlayer component.

export default function ProjectDetail(props) {
  return (
    <>
      <div>
        <ReactPlayer 
           url={props.videoUrl}  // does not work!
           width="500px"
        />
      </div>
      <div>
        <h2>{props.title}</h2>  // works
        <p>{props.desc}</p>     // works
        <button 
          onClick={() => { window.open(props.sourceUrl, "_blank"); }}  // works
        > Click to see more
        </button>
      </div>
    </>
  );
}

title, desc and sourceUrl are working fine, but I don't understand videoUrl doesn't. I tried looking up an answer but was unsuccessful.

If I import videoSample in file 3 directly, it works fine, but not when passed as a prop from outside. What am I missing?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Found my mistake. All I needed to do was removing the curly brackets.

videoUrl: { videoSample } -> videoUrl: videoSample

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda