I am trying to create elements with React dynamically, but I cannot use it correctly this.props. I currently have no new items. I tried looking at other answers and imitating them, but without any luck.
React.createClass({
getDefaultProps: function() {
var items = [];
chrome.storage.local.get(null, function(result) {
var keys = Object.keys(result);
for (var i = 0; i < keys.length; i++) {
items.push(keys[i]);
}
})
return {
items: items
}
},
render: function() {
return (
<div>
{this.props.items.map(function loop(item, i) {
return (<div>{item}</div>)
})}
</div>
)
}
})
However, when I substitute a literal array for this.props.items, I get new elements. Any ideas what I'm missing here?
source
share