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

211
Views
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 answers
Answer question

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 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!