Created
November 10, 2014 12:22
-
-
Save mikaelbr/6f824e80f3aaf96c2bd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TestList = React.createClass({ | |
render: function() { | |
var i = 0; | |
var items = this.props.items.map(function(item) { | |
return ( | |
<div key={i++}>{item.name}</div> | |
); | |
}); | |
return ( | |
<div> | |
<div>{items}</div> | |
<button onClick={this.props.addItem}>Legg til</button> | |
</div> | |
); | |
} | |
}); | |
var TestForm = React.createClass({ | |
getInitialState: function() { | |
return { items: [] }; | |
}, | |
addItem: function () { | |
// Don't mutate the item in state/props | |
this.setState({ | |
items: this.state.items.concat('Tore Lervik') | |
}); | |
}, | |
render: function() { | |
return ( | |
<div> | |
<TestList items={this.state.items} addItem={this.addItem} /> | |
<button onClick={this.showLog}>Vis logg</button> | |
</div> | |
); | |
}, | |
showLog: function() { | |
console.log(this.state.items); | |
} | |
}); | |
React.render(<TestForm/>, document.getElementById("example")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment