Running into issues when I deployed the drum machine project to get it graded. I got it working on my local development project (only issue is react would give errors due to pause() being used after my play()), but when I deployed to github to grade it, test 5, 6, and 7 started failing.
I am getting an error that’s occurring on my drum pad component Uncaught TypeError: Cannot read properties of null (reading 'play') but it’s hard to tell why it’s suddenly turning null.
Github Page (Failing): React App (innocent-traitor.github.io)
My drum pad script:
import './Drum_Pad.css';
import { useEffect } from 'react';
function DrumPad({soundID, text, audioSrc, parentCallback}) {
useEffect(() => {
const handleKeyPress = (e) => {
const key = e.key;
if (key === text.toLowerCase() || key.toUpperCase() === text) {
handleClick();
}
};
document.addEventListener('keydown', handleKeyPress);
return () => {
document.removeEventListener('keydown', handleKeyPress);
}
});
const snd = document.getElementById(text);
const playSound = () => {
snd.play();
snd.currentTime=0;
}
const handleClick = () => {
playSound();
parentCallback(soundID);
}
return (
<div className="drum-pad-div">
<button
className='drum-pad'
onClick={handleClick}
id={soundID}
>
<audio className='clip' src={audioSrc} id={text}></audio>
{text}
</button>
</div>
);
}
export default DrumPad;