function useState(defaultValue) {
let currentState = defaultValue;
function stateSetter(value) {
//console.log(value);
currentState = value;
return currentState;
}
return [currentState, stateSetter];
}
const [count, setCount] = useState(0);
setCount(count + 1);
console.log(count);
useEffect(() => {
function handleNext() {
dispatch(nextAudio());
}
player.addEventListener('ended', handleNext);
return () => player.removeEventListener('ended', handleNext);
}, []);
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { playAudio, nextAudio, prevAudio } from './../slices/playlistSlice.js';
export default function Control() {
const dispatch = useDispatch();
const id = useSelector((state) => state.playlist.id);
const player = useSelector((state) => state.playlist.audio);
const flag = useSelector((state) => state.playlist.flag);
console.log(id);
function handleSuffle() {}
function handleRepeat() {}
//player.addEventListener('ended', () => dispatch(playAudio(id++)));
//player.addEventListener('ended', () => dispatch(nextAudio(id)));
useEffect(() => {
function handleNext() {
dispatch(nextAudio());
}
player.addEventListener('ended', handleNext);
return () => player.removeEventListener('ended', handleNext);
}, []);
//player.addEventListener('ended', () => dispatch(nextAudio(id)));
return (
<div className="controls_wrapper">
<div className="controls_btn_suffle" onClick={handleSuffle}>
<svg className="icon">
<use xlinkHref="icons.svg#icon-suffle"></use>
</svg>
</div>
<div
className="controls_btn_prev"
onClick={() => dispatch(prevAudio(id))}
>
<svg className="icon">
<use xlinkHref="icons.svg#icon-prev"></use>
</svg>
</div>
<div
className="controls_btn_pause"
onClick={() => dispatch(playAudio(id))}
>
{flag ? (
<svg className="icon">
<use xlinkHref="icons.svg#icon-pause"></use>
</svg>
) : (
<svg className="icon">
<use xlinkHref="icons.svg#icon-play"></use>
</svg>
)}
</div>
<div
className="controls_btn_next"
onClick={() => dispatch(nextAudio(id))}
>
<svg className="icon">
<use xlinkHref="icons.svg#icon-next"></use>
</svg>
</div>
<div className="controls_btn_repeat" onClick={handleRepeat}>
<svg className="icon">
<use xlinkHref="icons.svg#icon-repeat"></use>
</svg>
</div>
</div>
);
}