Created
February 6, 2016 17:07
-
-
Save laere/76f0c1884bcc5ec737ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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