Last active
June 24, 2019 01:58
-
-
Save J3698/81847f75bb68af1f9264dc10e10a1347 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 './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {dataText: "data not yet recieved"}; | |
} | |
// this is called once the component is rendered at least once | |
componentDidMount() { | |
fetch("/greet") | |
.then(data => data.text()) | |
.then(text => this.updateRecievedText(text)); | |
} | |
updateRecievedText(text) { | |
if (text == "hi") { | |
this.setState({dataText: "Talking to Express server"}); | |
} else { | |
this.setState({dataText: "This isn't the Express server"}); | |
} | |
} | |
render() { | |
return ( | |
<div className="App"> | |
Status: {this.state.dataText} | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment