because BackgroundMusic was a regular component
any rerenders caused the play function to be called
(despite having a hasPlayed ref which should have
persisted across re-renders which I dont understand,
but whats understandable eis that the useSound hook
got a different data parameter and that caused the
data.isPlaying to be a false negative). Another way
to have fixed this might have been wrapping this
component in some sort of memoization React structure
that would only re-render this component if the given
props have changed (but on second thought this might
not have worked, because the BackgroundMusic
component was only rerendered because the parent
AddFriends was rerendererd as well...
I've decided to change the BackgroundMusic
component to be a context, but I don't think it being
now a context is what fixed it but rather that it is
higher in the DOM hierarchy so it only reloads on
the page changing (?) not sure exactly
the MusicProvider is using a context internally
so i think this should now enable some UI to be able
to change settings like whether sound can play etc.
because BackgroundMusic was a regular component any rerenders caused the play function to be called (despite having a hasPlayed ref which should have persisted across re-renders which I dont understand, but whats understandable eis that the useSound hook got a different
data
parameter and that caused thedata.isPlaying
to be a false negative). Another way to have fixed this might have been wrapping this component in some sort of memoization React structure that would only re-render this component if the given props have changed (but on second thought this might not have worked, because theBackgroundMusic
component was only rerendered because the parentAddFriends
was rerendererd as well...I've decided to change the
BackgroundMusic
component to be a context, but I don't think it being now a context is what fixed it but rather that it is higher in the DOM hierarchy so it only reloads on the page changing (?) not sure exactlythe
MusicProvider
is using a context internally so i think this should now enable some UI to be able to change settings like whether sound can play etc.