Skip to content

Instantly share code, notes, and snippets.

@kvedantmahajan
Last active July 27, 2017 08:09
Show Gist options
  • Save kvedantmahajan/40b43c532b66561172d34fb125f0a719 to your computer and use it in GitHub Desktop.
Save kvedantmahajan/40b43c532b66561172d34fb125f0a719 to your computer and use it in GitHub Desktop.
A basic React app.js to demonstrate connectivity to Node/Express APIs
import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
state = {notes: []};
componentDidMount() {
fetch('/api/notes')
.then(res => res.json())
.then(notes => this.setState({notes}));
}
render() {
return (
<div className="App">
<img className="logo" src={logo} alt="Logo"/>
<h1>Notes</h1>
{this.state.notes.map(note =>
<div key={note.id}>
<span>{note.title}</span>- <span>{note.text}</span>
</div>
)}
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment