joshwcomeau / use-sound

A React Hook for playing sound effects
MIT License
2.76k stars 98 forks source link

initial playbackRate and volume has no effect #9

Closed myagoo closed 4 years ago

myagoo commented 4 years ago

If I set an initial playbackRate or volume other than 1 and never change them, it will have no effect. Instead I must use the play options as follow play({playbackRate: 0.5}).

This is because there is no sound when the following effect run for the first (and in my case, also last) time: https://github.com/joshwcomeau/use-sound/blob/master/src/index.ts#L74

The workaround is to use the play options instead.

Anyway, great work and great blog post ! I'm working on a side project that will make good use of sounds (I hope) thanks to you !

myagoo commented 4 years ago

trying to circumvent rules-of-hooks is always risky. Maybe you could try to set initial options here : https://github.com/joshwcomeau/use-sound/blob/master/src/index.ts#L56