Video displayed in ReactJS component not updating

前端 未结 5 1401

I\'m new to ReactJS (0.13.1), and I\'ve created a component in my app to display HTML5 video.

It seems to work perfectly but only for the first selection. The vid

5条回答
  •  孤城傲影
    2020-12-18 23:17

    Try this way

    import React, { Component } from "react";
    
    class Video extends Component {
    
      video: any = React.createRef();
    
      componentDidUpdate(preProps: any) {
        const { url } = this.props;
        if (preProps && preProps.url && url) {
          if (preProps.url !== url) {
            this.video.current.src = url;
          }
        }
      }
    
      render() {
        const { url } = this.props;
        return (
          
        );
      }
    }
    

提交回复
热议问题