React Fundamentals - Básico States

React Fundamentals - Básico States

by Angelo Rogério Rubin

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.2/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.2/react-with-addons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.2/react.min.js"></script>
<script type="text/jsx">
    var App = React.createClass({
        getInitialState:function(){
            return {
              txt: 'default state txt',
              id: 0
            }
        },
        update: function(e){
            this.setState(
                {
                    txt: e.target.value
                }
            );
        },
        render:function(){
            return (
                <div>
                    <input type="text" onChange={this.update} />
                    <h1>{this.state.txt}</h1>
                </div>
            );
        }
    });
    React.render(<App txt="this is the txt prop"  />, document.body);
</script>