I'm trying to make a tapper component where everytime a user clicks on the button the number inside of the component goes up one.
The tapper component gets an initial value from a local json file. When the tapper is pressed however it fired the onClick function but doesn't update the state so the number doesn't go up! I'm new to react so I don't know if I'm approching this problem incorrectly.
My intent in the future is for the button to update the json value so that anyone people who visit the page in the future can hit it and make the number go up.
import React, {Component} from 'react';
import {Icon, Label} from 'semantic-ui-react';
import tapperValue from './tappervalue.json';
export default class TapperOutput extends Component {
constructor() {
super();
this.state = {
tapperValue: tapperValue.tapperValue
}
}
handleClick = () => {
console.log('Before the conversion ' + this.state.tapperValue);
const taps = this.state.tapperValue + 1;
this.setState = ({tapperValue: taps});
console.log('After the conversion ' + this.state.tapperValue);
}
render() {
return (
<Label onClick={this.handleClick}>
<Icon name='hand paper'/> {this.state.tapperValue}
</Label>);
}
}