Skip to content

Instantly share code, notes, and snippets.

@wnqueiroz
Created August 10, 2018 02:04
Show Gist options
  • Save wnqueiroz/31f432b09720d0bdc1d8292f16f3e893 to your computer and use it in GitHub Desktop.
Save wnqueiroz/31f432b09720d0bdc1d8292f16f3e893 to your computer and use it in GitHub Desktop.
React Context: Users.jsx with props from context
import React, { Component } from 'react'
import { getUsers } from '../services/api'
class Users extends Component {
state = {
loading: false
}
getUsers = async () => {
const { showLoading, hideLoading } = this.props
showLoading('Carregando usuários')
const response = await getUsers().then(response => {
hideLoading()
return response
})
console.log({ response })
}
render() {
return (
<button onClick={this.getUsers}>Buscar usuários</button>
)
}
}
export default Users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment