Skip to content

Instantly share code, notes, and snippets.

View rickyalmeidadev's full-sized avatar
👨‍💻
Learning something new everyday

Ricky Almeida rickyalmeidadev

👨‍💻
Learning something new everyday
View GitHub Profile
@rickyalmeidadev
rickyalmeidadev / .eslintrc.json
Last active November 12, 2021 19:52
Create React App eslint and prettier personal configuration
{
"extends": [
"react-app",
"react-app/jest",
"plugin:testing-library/react",
"plugin:jest-dom/recommended",
"plugin:prettier/recommended"
],
"plugins": ["testing-library", "jest-dom", "prettier"],
"rules": {
@rickyalmeidadev
rickyalmeidadev / config-overrides.js
Last active June 24, 2021 21:31
Emotion + Create React App
const { override, addBabelPreset } = require('customize-cra')
module.exports = override(addBabelPreset('@emotion/babel-preset-css-prop'))
@rickyalmeidadev
rickyalmeidadev / scrollbar.css
Created June 24, 2021 21:30
A Beatiful Scrollbar
body::-webkit-scrollbar {
background-color: #fff;
width: 16px;
}
body::-webkit-scrollbar-track {
background-color: #fff;
}
body::-webkit-scrollbar-thumb {
@rickyalmeidadev
rickyalmeidadev / config.js
Last active July 3, 2021 19:35
Adds a menu item to clear AsyncStorage in DevSettings
import { DevSettings, Platform, ToastAndroid } from 'react-native'
import AsyncStorage from '@react-native-async-storage/async-storage'
import Snackbar from 'react-native-snackbar'
DevSettings.addMenuItem('Clear AsyncStorage', async () => {
const keys = await AsyncStorage.getAllKeys()
await AsyncStorage.multiRemove(keys.filter(key => !key.includes('@REACTOTRON')))
const message = 'AsyncStorage has been cleared'
if (Platform.OS === 'android') {
ToastAndroid.show(message, ToastAndroid.SHORT)
@rickyalmeidadev
rickyalmeidadev / create-store.js
Created July 4, 2021 09:18
Simple implementation of Redux
const createStore = reducer => {
let state
let listeners = []
const getState = () => state
const dispatch = action => {
state = reducer(state, action)
listeners.forEach(listener => listener())
}
const subscribe = listener => {
@rickyalmeidadev
rickyalmeidadev / make-graphql-client.d.ts
Last active September 8, 2021 17:43
GraphQL client factory for Next.js
export type GraphQLQuery = string
export type GraphQLMutation = string
export type Variables = {
[key: string]: any
}
type QueryBody = {
query: GraphQLQuery
@rickyalmeidadev
rickyalmeidadev / add-pre-commit-hook.md
Last active October 23, 2021 01:29
Adding Pre Commit Hook
npx mrm@2 lint-staged
@rickyalmeidadev
rickyalmeidadev / .eslintrc.json
Created November 9, 2021 12:33
Vite React configuration
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"plugins": ["react", "@typescript-eslint", "prettier"],
"settings": {
@rickyalmeidadev
rickyalmeidadev / script.js
Created November 13, 2021 04:38
Codegen for src/components/index.js exports
// scripts/codegen/components.js
const fs = require('fs')
const path = require('path')
const header = '/**\n * This file is generated. Do not edit.\n */\n'
const code = fs
.readdirSync(path.join(__dirname, '..', '..', 'src', 'components'))
.filter(filename => !filename.endsWith('.js'))
.map(filename => `export {default as ${filename}} from './${filename}/${filename}'`)
@rickyalmeidadev
rickyalmeidadev / use-focus.js
Last active November 22, 2021 02:18
useFocus and useRefs hooks for React and React Native forms
import {useCallback} from 'react'
const useFocus = refs => {
const focus = useCallback(
name => {
refs?.[name]?.current?.focus?.()
},
[refs]
)