Created
August 10, 2018 02:04
-
-
Save wnqueiroz/31f432b09720d0bdc1d8292f16f3e893 to your computer and use it in GitHub Desktop.
React Context: Users.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 { 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