howler.js icon indicating copy to clipboard operation
howler.js copied to clipboard

howler.js caches event handler methods

Open milad-afkhami opened this issue 3 years ago • 1 comments

Hi i'm using "howler": "^2.2.3" with react "react": "^17.0.2". So far it was good but I found out that the onEnd handler gets cached and inside of the handler I can't get the updated value of my state, and whenever I try to access the state, I get the old initial value.

so I did this trick:

  1. I've created a mock state named songJustEnded.
  2. when instantiating howler constructor i do: onend: () => setSongJustEnded(true)
  3. in my codes, I listen to changes of the songJustEnded using useEffect and I call my onEnd handler.

Is there any fix for this or do I have to stick to this trick

milad-afkhami avatar Aug 01 '21 08:08 milad-afkhami