Others might run into this problem so I figured I might as well post the code inside the Client/Apps.js file that I used to get things working.
If you're starting a new React project, you're going to start with a function inside Client/App.js called, App(). This needs to be replaced by Render() and moved into App class. Please see below:
import React, {Component} from 'react'
import logo from './logo.svg';
import './App.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = { apiResponse: "" };
}
callAPI() {
fetch("http://localhost:9000/testAPI")
.then(res => res.text())
.then(res => this.setState({ apiResponse: res }));
}
componentDidMount() {
this.callAPI();
}
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<p className="App-intro">{this.state.apiResponse}</p>
</div>
);
}
}
export default App;
Others might run into this problem so I figured I might as well post the code inside the Client/Apps.js file that I used to get things working.
If you're starting a new React project, you're going to start with a function inside Client/App.js called,
App(). This needs to be replaced byRender()and moved intoAppclass. Please see below: