React 18 adds onResize event to video elements

SyntheticEvent in React is a cross-browser wrapper similar to browers’s native events; It has the same interface as the browser’s native event, including stopPropagation() and preventDefault(), except the events work identically across all browsers.

Until React 18, React’s synthetic media events contain several existing media events, for instance onLoadedMetadata and onVolumeChange. But there is no onResize handler.


<video> element with a onResize prop would display a warning

Warning: Unknown event handler property `onResize`. It will be ignored.


With the changes in React 18, onResize props are added to <video> element that triggers when one or both of the videoWidth and videoHeight attributes have just been updated.

It’s useful for responding to resolution changes in video players.

Sample Code

import { useState } from "react";
import "./styles.css";

const VIDEO_LINKS = [

export default function App() {
  const [switchVideo, setSwitchVideo] = useState(0);
  const [videoWidth, setVideoWidth] = useState(null);
  const [videoHeight, setVideoHeight] = useState(null);

  return (
    <div className="App">
        style={{ width: videoWidth, height: videoHeight }}
        onResize={(e) => {
      <div className="resButton">
        <button onClick={() => setSwitchVideo(0)}>240p</button>
        <button onClick={() => setSwitchVideo(1)}>480p</button>
        <button onClick={() => setSwitchVideo(2)}>720p</button>

Need help on your Ruby on Rails or React project?

Join Our Newsletter