Skip to content

Instantly share code, notes, and snippets.

View akinncar's full-sized avatar

Akinn Rosa akinncar

View GitHub Profile
@akinncar
akinncar / TaskListContext.js
Last active October 11, 2020 16:11
TaskListContext
import React, { createContext, useState, useEffect } from 'react'
import uuid from 'uuid'
export const TaskListContext = createContext()
const TaskListContextProvider = props => {
const initialState = JSON.parse(localStorage.getItem('tasks')) || []
const [tasks, setTasks] = useState(initialState)
const [filteredTasks, setFilteredTasks] = useState(initialState)
@akinncar
akinncar / App.js
Last active October 19, 2020 00:51
GLView Expo 3D Game Example
<GLView
style={{ flex: 1 }}
onContextCreate={async (gl) => {
// GL Parameter disruption
const { drawingBufferWidth: width, drawingBufferHeight: height } = gl;
// Renderer declaration and set properties
const renderer = new Renderer({ gl });
renderer.setSize(width, height);
renderer.setClearColor("#fff");
@akinncar
akinncar / SnackBarContext.tsx
Created February 1, 2021 16:33
SnackBar Material UI Context Typescript Boilerplate
import { Snackbar } from '@material-ui/core';
import { Alert, Color } from '@material-ui/lab';
import React, { createContext, useContext } from 'react';
type SnackBarContextActions = {
showSnackBar: (text: string, typeColor: Color) => void;
};
const SnackBarContext = createContext({} as SnackBarContextActions);
@akinncar
akinncar / reactJsLearningPath.md
Last active May 12, 2022 00:14
ReactJs Learning Path - Basics that you should learn
  • learn how to build JSX basic components
  • learn component props
  • learn how to manage state
  • learn basic hooks (useState and useEffect)
  • learn how to fetch Rest API's (Axios, SWR)
  • learn how to use routes with React Router DOM
  • learn how to manage global state (Context API, Redux, MobX)
  • learn how to make unit tests with Jest
  • learn how to use GraphQL (Apollo, Relay)
@akinncar
akinncar / useOutsideClick.ts
Last active March 17, 2021 22:28
Hook to catch click outside modal
import { useEffect, RefObject } from 'react';
export function useOutsideClick(ref: RefObject<HTMLInputElement>, callback) {
function handleClick(e: MouseEvent) {
if (ref.current === e.target) {
callback();
}
}
useEffect(() => {
@akinncar
akinncar / GadosCoin.sol
Last active June 6, 2021 02:49
GadosCoin Smart Contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract GadosCoin {
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) public allowance;
uint public totalSupply = 1000 * 10 ** 18;
string public name = "GadosCoin";
string public symbol = "GadosCoin";
uint public decimals = 18;
@akinncar
akinncar / example.ts
Created June 7, 2021 19:49
useClickOutside v2
useClickOutside({
isOpen,
ref: containerRef,
onRequestClose: () => setIsOpen(false),
})
@akinncar
akinncar / AuthContext.tsx
Last active November 3, 2023 01:51
AuthContext with NextJs + Nookies
import {
createContext,
ReactNode,
useContext,
useEffect,
useState,
} from 'react'
import { setCookie, parseCookies, destroyCookie } from 'nookies'
import Router from 'next/router'
@akinncar
akinncar / mockHooks.js
Created June 23, 2021 14:36
Mock custom hooks on jest
// outside component (after imports)
const useAuth = jest.spyOn(require('contexts/AuthContext'), 'useAuth')
const user = {
user: {
name: 'Roberto Firmino',
},
}
// inside describe
useAuth.mockReturnValue(user)
@akinncar
akinncar / mockRender.js
Created July 10, 2021 01:20
Mock contexts on testing library
import '__mocks__/broadcast'
import { ReactChildren, ReactChild } from 'react'
import { render } from '@testing-library/react'
import { GlobalStyles } from 'styles'
import { ToastContainer } from 'components/Toast'
import { AuthProvider } from 'contexts/AuthContext'
import { SidebarProvider } from 'contexts/SidebarContext'