0

I'm trying to change the color of some buttons onClick and getting this error, what can I do?

enter image description here

after adding const I now get then error TypeError: undefined is not an object (evaluating 'e.target.name') enter image description here

shange
  • 77
  • 7

2 Answers2

0

Add const in front of handleClick on line 44.

const handleClick = (e) => {
  //
}
Ryan
  • 1,151
  • 5
  • 7
  • I'm now getting the error undefined is not an object (evaluating 'e.target.name'), just to clarify I'm copying this code from a solution I saw on stack overflow: https://stackoverflow.com/questions/54665021/how-to-change-color-of-button-on-press-in-react-native – shange Oct 23 '22 at 11:50
-1

I think it is better for you to pass your variable instead of using default event value in handleClick().

onPress={()=>{
  this.handleClick("YOUR_VALUE");
}}

And you can create your own handleClick() like this.

handleClick = (data) =>{
  console.log(data); // <- should output "YOUR_VALUE"
}
kiuQ
  • 931
  • 14