Skip to content

Commit

Permalink
fix: React 17 issue with effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharma, Amit committed Jul 16, 2022
1 parent 755cdb3 commit 2834cbc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-video-player-extended",
"version": "7.0.10",
"version": "7.0.11",
"description": "React HTML5 video providing functionality for marking and selecting frames, jumping back and forth between frames based on the fps.",
"author": "Amitt K Sharma",
"license": "MIT",
Expand Down
13 changes: 7 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,20 @@ function VideoPlayer(props: Props) {
}

useEffect(() => {
playerEl.current.addEventListener('timeupdate', handleProgress)
playerEl.current.addEventListener('durationchange', handleDurationLoaded)
const instance = playerEl.current
instance.addEventListener('timeupdate', handleProgress)
instance.addEventListener('durationchange', handleDurationLoaded)
if (timeStart) {
seekToPlayer()
}
if (isPlaying) {
playerEl.current.play()
instance.play()
}

return () => {
if (playerEl && playerEl.current) {
playerEl.current.removeEventListener('timeupdate', handleProgress)
playerEl.current.removeEventListener('durationchange', handleDurationLoaded)
if (instance) {
instance.removeEventListener('timeupdate', handleProgress)
instance.removeEventListener('durationchange', handleDurationLoaded)
}
}
}, [])
Expand Down

0 comments on commit 2834cbc

Please sign in to comment.