I’m almost done with the FE Libraries Drum Machine project, but my code isn’t recognizing the props i’m passing as arguments to the handleKeyDown function, seeing any props I passed into handleClick without issue as undefined. Code is as follows:
App.js
componentDidMount() {
document.addEventListener("keydown", this.handleKeyDown);
}
componentWillUnmount() {
document.removeEventListener("keydown", this.handleKeyDown);
}
handleKeyDown = (e, src) => {
console.log(src);
};
handleClick = (name, src) => {
this.setState({ display: name });
new Audio(src).play();
};
<Button
handleClick={this.handleClick}
handleKeyDown={this.handleKeyDown}
display={this.state.display}
name={button.name}
key={button.key}
id={button.key}
src={button.src}
tabIndex="0"
/>
and Button.js:
const Button = ({ handleClick, handleKeyDown, name, id, src }) => {
return (
<div
onClick={() => handleClick(name, src)}
onKeyDown={e => handleKeyDown(e, src)}
className="drum-pad"
>
{id}
<audio className="clip" id={id} data={src} />
</div>
);
};