Reputation: 5352
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 .
Upvotes: 0
Views: 11458
Reputation: 77482
You 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>;
}
});
Upvotes: 3