reactjs - How can I detect when video finished playing react? -


since react uses lifecycle methods , virtual dom how can detect when video has finished playing. found question on stackoverflow suggested use componentwillunmount there's no point @ remove video dom, componentwillunmount won't fired...

how can detect when video finished playing react?

use ref callback obtain reference <video dom element when mounts.

<video ref={el => this.videoelement = el}></video> 

combine componentdidmount() add event listener video element. ended event you're looking for.

the ended event fired when playback or streaming has stopped because end of media reached or because no further data available.

componentdidmount() {     this.videoelement.addeventlistener("ended", mycallback); } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -