react-video-thumbnail icon indicating copy to clipboard operation
react-video-thumbnail copied to clipboard

(Bug) videoUrl does not get updated on props change

Open srivastava9 opened this issue 4 years ago • 3 comments

While using VideoThumbnail and changing the videoUrl of using props does not changes videoUrl and same thumbnail gets generated again

srivastava9 avatar Nov 02 '20 16:11 srivastava9

@brothatru Could you please look into this and tell me a turnaround as this library is very important for my project

srivastava9 avatar Nov 02 '20 16:11 srivastava9

Did you find a solution for this?

umer-qureshi avatar Nov 30 '20 12:11 umer-qureshi

Since this bug was making an issue, how i approached this was to use a timer to hide it for 100ms and so that it is forced to rerender. i ll post the code for it below.

const [
      forceRerender,
      setForceRerender,
  ] =useState(ZERO)
  useEffect(() => {
      if (src) {
          setForceRerender(ZERO)
     
      const timer = setTimeout(() => {
          setForceRerender(forceRerender+ ONE)
      }, HUNDRED)
      return () => clearTimeout(timer)
}
  }, [
      src,
  ])
return (
{ forceRerender > ZERO &&<VideoThumbnail
                          videoUrl={src}
                      />}
)

Where the src is the url incoming from the props. This worked out for me. Good luck! P.S in case the logic can be improved, please do let me know!

umer-qureshi avatar Nov 30 '20 12:11 umer-qureshi