Problem:
- Tombol repeat tidak berfungsi saat lagu selesai
- Event listener 'ended' menggunakan variabel state 'isRepeat' dari closure yang lama
- Meskipun state sudah di-toggle, event listener masih menggunakan nilai lama
Solution:
- Tambahkan isRepeatRef untuk menyimpan nilai terbaru dari isRepeat
- Sync ref dengan state menggunakan useEffect
- Gunakan isRepeatRef.current di event listener 'ended'
- Remove isRepeat dari dependency array useEffect
Files changed:
- src/app/context/MusicContext.tsx: Add isRepeatRef and sync with state
This ensures the repeat functionality works correctly when the song ends.
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>