Created
August 9, 2018 19:07
-
-
Save wnqueiroz/37137bb6f735e69a30649f046f6986f6 to your computer and use it in GitHub Desktop.
React Context: Users with Loading component
This file contains hidden or 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 { getUsers } from '../services/api' | |
| class Users extends Component { | |
| state = { | |
| loading: false | |
| } | |
| getUsers = async () => { | |
| this.setState({ loading: true }) | |
| const response = await getUsers().then(response => { | |
| this.setState({ loading: false }) | |
| return response | |
| }) | |
| console.log({ response }) | |
| } | |
| render() { | |
| const { loading } = this.state | |
| return ( | |
| <Fragment> | |
| <button onClick={this.getUsers}>Buscar usuários</button> | |
| <Loading loading={loading} message='Carregando usuários...' /> | |
| </Fragment> | |
| ) | |
| } | |
| } | |
| export default Users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment