-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from byandrev/dev
feat: add click sound effect
- Loading branch information
Showing
5 changed files
with
4,511 additions
and
4,399 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
const useAudio = (url) => { | ||
const [audio] = useState(new Audio(url)); | ||
const [playing, setPlaying] = useState(false); | ||
|
||
const toggle = () => setPlaying(!playing); | ||
|
||
useEffect(() => { | ||
playing ? audio.play() : audio.pause(); | ||
}, [audio, playing]); | ||
|
||
useEffect(() => { | ||
audio.addEventListener("ended", () => setPlaying(false)); | ||
return () => { | ||
audio.removeEventListener("ended", () => setPlaying(false)); | ||
}; | ||
}, [audio]); | ||
|
||
return { playing, toggle }; | ||
}; | ||
|
||
export default useAudio; |
Oops, something went wrong.