Created
August 9, 2018 19:11
-
-
Save wnqueiroz/06ca2919f509ebf23cc5263bd4e9fd7c to your computer and use it in GitHub Desktop.
React Context: Departments with Loading component
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, 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