Skip to content

Instantly share code, notes, and snippets.

@BTMPL
Created December 22, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BTMPL/a65bfbb74e84ce54d54246e491c4162e to your computer and use it in GitHub Desktop.
Save BTMPL/a65bfbb74e84ce54d54246e491c4162e to your computer and use it in GitHub Desktop.
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