Created
August 15, 2017 21:09
-
-
Save JoseGonzalez321/65d170dea085adb87fdd98ea243d5610 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
import React, {Component} from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import RobotMaster from './robotmaster'; | |
function RobotItem(props) { | |
return ( | |
<li> | |
{props.name} | |
</li> | |
) | |
} | |
class App extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
message: '', | |
robots: [] | |
} | |
} | |
componentDidMount() { | |
fetch('http://localhost:5000/api/robot') | |
.then(response => response.json()) | |
.then(json => { | |
this.setState({robots: json}); | |
}); | |
} | |
render() { | |
if (!this.state.robots) | |
return <p>loading...</p> | |
let stuff = this | |
.state | |
.robots | |
.map((robot, i) => { | |
return ( | |
<RobotMaster key={robot.id} {...robot}/> | |
) | |
}); | |
return ( | |
<div className="App"> | |
<div className="App-header"> | |
<img src={logo} className="App-logo" alt="logo"/> | |
<h2>Robot Masters 2.0</h2> | |
</div> | |
<div className="App-intro"> | |
{this.state.robots.length} | |
<ul> | |
{stuff} | |
</ul> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment