0

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 .

cfprabhu
  • 5,267
  • 2
  • 21
  • 30
  • Stackoverflow http://stackoverflow.com/questions/24502898/show-or-hide-element-in-react-js should help you – Davet Nov 25 '15 at 09:28

1 Answers1

3

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>;
    }
});

Example

Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144