Created
December 22, 2016 14:40
-
-
Save BTMPL/a65bfbb74e84ce54d54246e491c4162e 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 React = require("react"); | |
var Recipe = React.createClass({ | |
updateList: function() { | |
var list = []; | |
for (let i = 0; i < window.localStorage.length - 1; i++) { | |
var key = window.localStorage.key(i); | |
list.push(window.localStorage.getItem(key)); | |
} | |
this.setState({ | |
list: list | |
}); | |
} | |
componentDidMount: function() { | |
this.updateList(); | |
} | |
render: function() { | |
return ( | |
<div className="full-recipe"> | |
{this.state.list.map((item) => { | |
return ( | |
<div className="recipe"> | |
<h2>{item.name}</h2> | |
</div> | |
); | |
})} | |
<button onClick={() => this.updateList()}>refresh the list</button> | |
</div> | |
); | |
} | |
}); | |
module.exports = Recipe; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment