Skip to content

Instantly share code, notes, and snippets.

View wnqueiroz's full-sized avatar
:octocat:

William Queiroz wnqueiroz

:octocat:
View GitHub Profile
@wnqueiroz
wnqueiroz / mock.js
Last active August 9, 2018 16:18
React Context: mock.js
export const users = [{
id: 1,
first_name: "Giffy",
last_name: "Crookall",
email: "gcrookall0@dmoz.org",
gender: "Male"
}, {
id: 2,
first_name: "Dolli",
last_name: "Pochet",
@wnqueiroz
wnqueiroz / api.js
Created August 9, 2018 17:34
React Context: src/services/api.js
import { users, departaments } from '../mock'
export const getUsers = async () => {
return new Promise(resolve => setTimeout(() => {
resolve(users)
}, 2000))
}
export const getDepartments = async () => {
return new Promise(resolve => setTimeout(() => {
@wnqueiroz
wnqueiroz / Users.jsx
Created August 9, 2018 17:51
React Context: src/components/Users.jsx
import React, { Component } from 'react'
import { getUsers } from '../services/api'
class Users extends Component {
getUsers = async () => {
const response = await getUsers()
console.log({ response })
}
@wnqueiroz
wnqueiroz / Departments.jsx
Created August 9, 2018 17:53
React Context: src/components/Departments.jsx
import React, { Component } from 'react'
import { getDepartments } from '../services/api'
class Departments extends Component {
getDepartments = async () => {
const response = await getDepartments()
console.log({ response })
}
@wnqueiroz
wnqueiroz / App-with-components.jsx
Last active August 9, 2018 18:58
React Context: App.jsx with Users and Departments components
import React, { Component, Fragment } from 'react'
import Departments from './components/Departments'
import Users from './components/Users'
import './index.css'
class App extends Component {
render() {
return (
@wnqueiroz
wnqueiroz / index.css
Last active August 9, 2018 18:52
React Context: index.css
.overlay-content {
display: flex;
width: 100%;
left: 0;
top: 0;
align-items: center;
height: 100%;
justify-content: center;
position: fixed;
z-index: 999999;
@wnqueiroz
wnqueiroz / Loading.jsx
Created August 9, 2018 19:02
React Context: src/components/Loading.jsx
import React from 'react'
import Spinner from 'react-spinkit'
const Loading = ({ loading, message }) => {
return loading ? (
<div className='overlay-content'>
<div className='wrapper'>
<Spinner
name='pacman'
@wnqueiroz
wnqueiroz / Users.jsx
Created August 9, 2018 19:07
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
@wnqueiroz
wnqueiroz / Departments.jsx
Created August 9, 2018 19:11
React Context: Departments with Loading component
import React, { Component, Fragment } from 'react'
import Loading from './Loading'
import { getDepartments } from '../services/api'
class Departments extends Component {
state = {
loading: false
@wnqueiroz
wnqueiroz / App-with-loading-context.jsx
Last active August 10, 2018 02:16
React Context: App.jsx with loading context
import React, { Component, Fragment } from 'react'
import Departments from './components/Departments'
import Users from './components/Users'
import './index.css'
const LoadingContext = React.createContext({
loading: false,
message: null,