Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda