Skip to content

Commit

Permalink
Flux - 11 - Fetching Data Naively
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jul 5, 2015
1 parent 42bcfc6 commit f6c8c35
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions imgur-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"react": "^0.13.3",
"react-router": "^1.0.0-beta2",
"reactify": "^1.1.0",
"reflux": "^0.2.8",
"vinyl-source-stream": "^1.1.0",
"watchify": "^2.4.0",
"whatwg-fetch": "^0.9.0"
Expand Down
24 changes: 23 additions & 1 deletion imgur-client/src/components/topic-list.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
var React = require('react');
var Api = require('../utils/api');

module.exports = React.createClass({
getInitialState: function() {
return {
topics: []
}
},
componentWillMount: function() {
Api.get('topics/defaults')
.then(function(data){
this.setState({
topics: data.data
})
}.bind(this));
},
render: function() {
return <div className="list-group">
Topic List
{this.renderTopics()}
</div>
},
renderTopics: function() {
return this.state.topics.map(function(topic){
return <li>
{topic}
</li>
});
}
})
});

1 comment on commit f6c8c35

@mihirchronicles
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncaught (in promise) TypeError: Cannot read property 'data' of undefined(…)

It seems like data is not defined here. Do you have to pass data as a parameter in componentWillMount function?

Please sign in to comment.