Created
August 10, 2018 02:02
-
-
Save wnqueiroz/542d7ef2af122a0b20d4577345bbf1ce to your computer and use it in GitHub Desktop.
React Context: Departments.jsx with props from context
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 { getDepartments } from '../services/api' | |
class Departments extends Component { | |
state = { | |
loading: false | |
} | |
getDepartments = async () => { | |
const { showLoading, hideLoading } = this.props | |
showLoading('Carregando departamentos') | |
const response = await getDepartments().then(response => { | |
hideLoading() | |
return response | |
}) | |
console.log({ response }) | |
} | |
render() { | |
return ( | |
<button onClick={this.getDepartments}>Buscar departamentos</button> | |
) | |
} | |
} | |
export default Departments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment