Skip to content

Instantly share code, notes, and snippets.

@wnqueiroz
Created August 9, 2018 19:11
Show Gist options
  • Save wnqueiroz/06ca2919f509ebf23cc5263bd4e9fd7c to your computer and use it in GitHub Desktop.
Save wnqueiroz/06ca2919f509ebf23cc5263bd4e9fd7c to your computer and use it in GitHub Desktop.
React Context: Departments with Loading component
import React, { Component, Fragment } from 'react'
import Loading from './Loading'
import { getDepartments } from '../services/api'
class Departments extends Component {
state = {
loading: false
}
getDepartments = async () => {
this.setState({ loading: true })
const response = await getDepartments().then(response => {
this.setState({ loading: false })
return response
})
console.log({ response })
}
render() {
const { loading } = this.state
return (
<Fragment>
<button onClick={this.getDepartments}>Buscar departamentos</button>
<Loading loading={loading} message='Carregando departamentos...' />
</Fragment>
)
}
}
export default Departments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment