решить проблему с использованием ref
атрибута JSX
import React, { useState, useEffect } from 'react';
import './audioPlayer.css';
interface AudioPlayerProps {
music: string,
}
const AudioPlayer: React.FC<AudioPlayerProps> = ({ music}) => {
const [audio, setAudio] = useState();
useEffect(() => {
if(audio){
audio.pause();
audio.load();
audio.play();
}
}, [music,audio]);
return (
<audio ref={(audioref)=>{ setAudio(audioref) }} >
<source src={music} type="audio/mpeg" />
Your browser does not support the audio tag.
</audio>
);
};
export default React.memo(AudioPlayer,(prevProps, nextProps)=>{
return prevProps.music === nextProps.music
});