Last active
June 4, 2018 16:08
-
-
Save bookercodes/028b0d22842dfd5e9d908f9897f331f6 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
// ./src/App.js | |
import React, { Component } from 'react' | |
import UsernameForm from './UsernameForm' | |
class App extends Component { | |
state = { | |
currentUsername: null, | |
currentId: null | |
} | |
onUsernameSubmitted = username => { | |
fetch('http://localhost:3001/users', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ username }) | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
this.setState({ | |
currentId: data.id, | |
currentUsername: data.name | |
}) | |
}) | |
.catch(error => { | |
console.error('error', error) | |
}) | |
} | |
render() { | |
return <UsernameForm handleSubmit={this.onUsernameSubmitted} /> | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment