Skip to content

Instantly share code, notes, and snippets.

@wnqueiroz
Created August 9, 2018 19:07
Show Gist options
  • Select an option

  • Save wnqueiroz/37137bb6f735e69a30649f046f6986f6 to your computer and use it in GitHub Desktop.

Select an option

Save wnqueiroz/37137bb6f735e69a30649f046f6986f6 to your computer and use it in GitHub Desktop.
React Context: Users with Loading component
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