Skip to content

Instantly share code, notes, and snippets.

@wnqueiroz
Created August 10, 2018 02:02
Show Gist options
  • Save wnqueiroz/542d7ef2af122a0b20d4577345bbf1ce to your computer and use it in GitHub Desktop.
Save wnqueiroz/542d7ef2af122a0b20d4577345bbf1ce to your computer and use it in GitHub Desktop.
React Context: Departments.jsx with props from context
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