Audio is not defined
#17963
-
I tried to play an audio file when a button is triggered like the code below. const [audio] = useState(new Audio(URL))
audio.play() but it's saying |
Beta Was this translation helpful? Give feedback.
Answered by
c0b41
Oct 17, 2020
Replies: 1 comment 2 replies
-
because you can't run Audio api on server const [audio, setAudio] = useState(null)
useEffect(() => {
setAudio(new Audio(URL)) // only call client
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
jamesmosier
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
because you can't run Audio api on server