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

209
Vistas
How to add a videojs plugin on React hooks

I created a functional React component to render a videojs player which works really well, but now I'm trying to add a plugin (in this case I'm trying with videojs-preview: https://www.npmjs.com/package/videojs-preview) and it fails. Here is my component:

import React, { useCallback, useEffect, useState } from 'react';
import videojs from 'video.js';
import preview from 'videojs-preview';

const Player = (props) => {
  const [videoEl, setVideoEl] = useState(null);
  const onVideo = useCallback((el) => {
    setVideoEl(el);
  }, []);

  useEffect(() => {
    if (videoEl == null) return;
    videojs.registerPlugin('videojs-preview', preview);
    videojs(videoEl, { ...props }, () => {
      videojs.preview();
    });
  }, [props, videoEl]);

  return (
    <div data-vjs-player>
      <video ref={onVideo} className="video-js vjs-big-play-centered mt-10" playsInline crossOrigin="anonymous" height={630} autoPlay />
    </div>
  );
};

export default Player;

The error I'm getting is: TypeError: video_js__WEBPACK_IMPORTED_MODULE_2___default(...).preview is not a function

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

0

The plugin registers itself so videojs.registerPlugin() is not needed.

Just import as import 'videojs-preview';, and init the plugin on the player instance rather than videojs.

const player = (playerRef.current = videojs(videoElement, options, () => {
  player.preview();
}));

An example with a different plugin but the same principle is at https://codesandbox.io/s/video-js-seek-buttons-react-vl7ux

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