Of course, the value is the string '2' not the number 2.
You need to use parseInt.
let newValue = parseInt(item.value) + 1;
I am building a calc in reactjs,. just copying the windows scientific calc. There are many buttons so I am trying to keep everything together so I stuck all button data inside an array of objects.
I am trying to add an int to the end of the current int, eg, 1, = 12. The logic below should work, I am sure, but I guess I am missing something.
{ id: 27, value: '2', function: () => { let x = current.toString() + buttons[27].value; setCurrent(x) }, className: 'bg-yellow-200 hover:bg-yellow-400' },
Okay, it was weird, but I fixed it. I have to two variables, one being typical and another being useState. I have to set the typical variable and then set it to use state, for some reason, grabbing the useState var, updating it and placing it back it just doesn't want to do it. Strange behavior.
Please or to participate in this conversation.