I'm trying to make a simple reset button, using onClick to send a string to a function.
<button
type='reset'
value='Reset'
id='reset-btn'
onClick={() => {
this.onInputChange('0')
}}
>
Reset
</button>
I have onInputChange function that takes an input value. With console.log(event) in onInputChange function, I know that I passed the argument from onClick, because I can the argument print in the console.
onInputChange = (event) => {
console.log('event: ', event);
let eventString = event.target.value;
let validArray = eventString.split('');
// Allow only binary digits in the input
for (let i=0; i < eventString.length; i++) {
if (validArray[i] !== '0' && validArray[i] !== '1') {
validArray.splice(i, 1);
event.target.value = validArray.join('');
}
}
return this.bin2Dec(validArray.join(''));
}
So why my app break and I get TypeError: Cannot read property 'value' of undefined?
this.onInputChange('0')with'0'? Why notonClick={onInputChange}?