Created
August 27, 2018 04:55
-
-
Save hugesean/5cf2291a695464374a0d154d4fe1cfe2 to your computer and use it in GitHub Desktop.
This file contains 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
import React, {Component,PropTypes} from 'react' | |
import './characters.css'; | |
class Characters extends Component{ | |
constructor(props) { | |
super(props); | |
} | |
componentDidMount() { | |
var sess=this; | |
this.getCharacters().then((data) => { | |
sess.setState({ characters: data }) | |
}); | |
} | |
getCharacters() { | |
var response={}; | |
var sess=this; | |
return new Promise((resolve,reject) => { | |
fetch('https://<YOUR APP ID>.execute-api.<YOUR AWS REGION>.amazonaws.com/latest/characters', { | |
method: 'GET', | |
headers: new Headers({ | |
'Content-Type': 'application/json', | |
'Accept': 'application/json', | |
}) | |
}).then(results=>{ | |
results.json().then(function(data) { | |
resolve(data); | |
}); | |
}); | |
}); | |
} | |
render() { | |
var rows; | |
if(this.state!=null) | |
{ | |
rows = this.state.characters.map((character) =>{ | |
return <tr><td>{character.characterId}</td><td>{character.name}</td><td>{character.actor}</td><td>{character.description}</td><td>{character.debut}</td></tr> | |
}); | |
} | |
return ( | |
<div className="container"> | |
<div className="App"> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>ID</th> | |
<th>Name</th> | |
<th>Actor</th> | |
<th>Description</th> | |
<th>Debut</th> | |
</tr> | |
</thead> | |
{rows} | |
</table> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default Characters; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment