I've been working on a chat App I want to play a sound whenever my data changes.
useEffect(()=>{
window.scrollTo(0,document.body.scrollHeight)
var notifyAudio = new Audio('../../public/Files.Notify.wav')
notifyAudio.loop = false
notifyAudio.play()
},[messages])
But, I end up with this error
"Uncaught (in promise) DOMException: play() failed because the
user didn't interact with the document first"
How I can get this type of functionality in my app?
This React Library allows us to autoplay sound and it's working fine. https://github.com/joshwcomeau/use-sound