I am learning Onsen-ui React and button to reset state is not working.
See below a simple test case
´´´
class MyApp extends Component {
constructor(props) {
super(props);
this.state = { myVal: 123 };
}
clickTest() {
this.setState({ myVal:456 });
}
render() {
return (
<Page>
<div id="test">{this.state.myVal}</div>
<ons-button onClick="clickTest()">test</ons-button>
<ons-button onPress={() => { this.setState({ myVal:999}); }}>test</ons-button>
</Page>
);
}
}
My kidney for a good answer ;-) its bugging me for days
I want to change the state of myVal with ons-button and react
There are a few problems with this code:
this
for theclickTest
function:this.clickTest = this.clickTest.bind(this);
onClick
isonClick={this.clickTest}
notonClick="clickTest()"
.onPress
is not a validons-button
prop; it should beonClick
.This is the fixed code:
One kidney please.
Reference