Guest User

Untitled

a guest
Nov 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class App extends Component {
  2.  
  3. render() {
  4. console.log(this.props);
  5. return (
  6. <div id="root">
  7. <div className="main">
  8. <Header />
  9. <Timeline login={this.props.params.login}/>
  10. </div>
  11. </div>
  12. );
  13. }
  14. }
  15.  
  16. export default class Timeline extends Component {
  17.  
  18. constructor() {
  19. super();
  20. this.state = {fotos: []};
  21. }
  22.  
  23. componentDidMount() {
  24.  
  25. let urlPerfil;
  26.  
  27. if(this.props.login === undefined) {
  28. urlPerfil = `http://localhost:8080/api/fotos?X-AUTH-TOKEN=${localStorage.getItem('auth-token')}`;
  29. } else {
  30. urlPerfil = `http://localhost:8080/api/public/fotos/${this.props.login}`;
  31. }
  32.  
  33. fetch(urlPerfil)
  34. .then(response => response.json())
  35. .then(fotos => {
  36. this.setState({fotos: fotos});
  37. });
  38. }
  39.  
  40. render(){
  41. return (
  42. <div className="fotos container">
  43. {
  44. this.state.fotos.map(foto => <FotoItem key={foto.id} foto={foto} />)
  45. }
  46. </div>
  47. );
  48. }
  49. }
Add Comment
Please, Sign In to add comment