score:1

Accepted answer

correct syntax would be

this.refs[soundname].play()

not sure about react though.

more info : https://www.w3schools.com/js/js_properties.asp

score:0

please note that using string literals as refs is deprecated.

instead, use functional refs:

<audio ref={(el) => this.jammedref = el} src={jammedsound}></audio>
<audio ref={(el) => this.budgeref = el} src={budgesound}></audio>

and the function itself looks like this:

playsound(soundname){
  this[`${soundname}ref`].play();
}

Related Query

More Query from same tag