gajus/youtube-player

Event handlers cannot be overwritten - With react

Titoine opened this issue · 3 comments

Hi,

I'm using your youtube-player with react and I pleased of how it work but I have a problem when I want to destroy and recreate a player.

If you don't know how react work there is the event componentDidMount and componentWillUnmount that are called when the component is created and destroyed.

At componentWillUnmount I create the player and bind one event.
When componentWillUnmount is launch (changing page for example) I unbind the player event.
But when I create again the player (componentWillUnmount ) I got this error :

Event handlers cannot be overwritten

Is there something else I should do when I when to delete the player ?

Same issue. How can we destroy all event listeners associated with this?

gajus commented

Sounds like a deficiency.

PR is welcome.

Maybe it's late but i was searching for the answer also.. This happens because YouTube creation function returns promise so before the next render there is no youtupe player yet, that's why destroy doesn't work properly and creating new player causes override of events