Skip to content

Instantly share code, notes, and snippets.

@laere
Created February 6, 2016 17:07
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 laere/76f0c1884bcc5ec737ce to your computer and use it in GitHub Desktop.
Save laere/76f0c1884bcc5ec737ce to your computer and use it in GitHub Desktop.
var React = require('react');
var Search = require('./Search.jsx')
var Img = require('./Img.jsx');
var Info = require('./Info.jsx');
var UI = React.createClass({
getInitialState: function() {
return {
people: []
}
},
// THIS WILL RETURN API JSON DATA BEFORE FIRST RENDER
componentDidMount: function() {
fetch('http://swapi.co/api/people')
.then(function(response) {
return response.json
})
.then(function(json) {
this.setState({ people: json });
})
.catch(function(err) {
console.log(err);
})
console.log(this.state.people);
},
filterByName: function(name) {
var filtered = this.state.people.filter(function(name) {
return obj.name.indexOf(name) > -1;
});
console.log(this.state.people)
return ({filtered});
console.log(filtered);
},
render: function() {
return (
<div className="ui">
<header className="search-bar">
{/*SEARCH BAR TO LOOK UP API INFO*/}
<Search onNewSearch={this.filterByName} characters={this.state.people} />
</header>
<input type="submit" value="search" onClick={this.filterByName} />
<Img />
<Info />
</div>
);
}
});
module.exports = UI;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment