I have list of songs with play button. I want to toggle button text to play/pause accordingly.
I have set ref for play/pause <span>
and trying to hide/show on button click.
this.refs.play.hide().
But this is giving error
Uncaught TypeError: _this.refs.play.hide is not a function at Song._this.play
Here is my react component code.
class Song extends React.Component {
play = (event) => {
this.refs.play.hide()
console.log(this.refs.play);
}
render() {
return (
<div>
<ul>
<li>Song 1 <button onClick={this.play}><span ref="play">play</span> <span className='hide' ref="pause"> Pause</span></button></li>
<li>Song 2 <button onClick={this.play}><span ref="play">play</span> <span className='hide' ref="pause"> Pause</span></button></li>
<li>Song 3 <button onClick={this.play}><span ref="play">play</span> <span className='hide' ref="pause"> Pause</span></button></li>
</ul>
</div>
);
}
}