I am the newer for React js. How can i achieve the following logic using react js
Here is two div's and one button. When the user click the button these div should toggle .
I am the newer for React js. How can i achieve the following logic using react js
Here is two div's and one button. When the user click the button these div should toggle .
Share edited Nov 23, 2015 at 20:12 cfprabhu asked Nov 23, 2015 at 20:03 cfprabhucfprabhu 5,3622 gold badges22 silver badges33 bronze badges 1- Stackoverflow stackoverflow./questions/24502898/… should help you – Davet Commented Nov 25, 2015 at 9:28
1 Answer
Reset to default 3You can use states
, like this
var Component = React.createClass({
getInitialState: function () {
return {
outsideText: 'Outside',
insideText: 'Inside'
}
},
handleClick: function () {
this.setState({
outsideText: this.state.insideText,
insideText: this.state.outsideText
})
},
render: function() {
return <div>
<div>
{ this.state.outsideText }
<div>
{ this.state.insideText }
</div>
</div>
<button onClick={this.handleClick}>Change Text</button>
</div>;
}
});
Example