Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active June 24, 2019 01:58
Show Gist options
  • Save J3698/81847f75bb68af1f9264dc10e10a1347 to your computer and use it in GitHub Desktop.
Save J3698/81847f75bb68af1f9264dc10e10a1347 to your computer and use it in GitHub Desktop.
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