Skip to content

Instantly share code, notes, and snippets.

@bookercodes
Last active June 4, 2018 16:08
Show Gist options
  • Save bookercodes/028b0d22842dfd5e9d908f9897f331f6 to your computer and use it in GitHub Desktop.
Save bookercodes/028b0d22842dfd5e9d908f9897f331f6 to your computer and use it in GitHub Desktop.
// ./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