Last active
July 27, 2017 08:09
-
-
Save kvedantmahajan/40b43c532b66561172d34fb125f0a719 to your computer and use it in GitHub Desktop.
A basic React app.js to demonstrate connectivity to Node/Express APIs
This file contains 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'; | |
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