Skip to content

Instantly share code, notes, and snippets.

View gaurangrshah's full-sized avatar
💭
🚀

gshah2020 gaurangrshah

💭
🚀
View GitHub Profile
@gaurangrshah
gaurangrshah / AddContact.js
Created February 22, 2019 18:50
component question
import React, { Component } from 'react';
import { Consumer } from '../../context';
import TextInputGroup from '../../components/layout/TextInputGroup';
import uuid from 'uuid';
class AddContact extends Component {
state = {
name: '',
email: '',
phone: '',
@gaurangrshah
gaurangrshah / node - .gitignore
Last active December 15, 2019 05:15
node gitignore
# OS X
.DS_Store*
Icon?
._*
# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
@gaurangrshah
gaurangrshah / netlify-form.js
Created May 16, 2019 00:59
netlify form boilerplate - no js needed
import React from 'react';
export default () => {
return (
<div className="call mt-5 w-10 ml-7">
<div className="call-box-top">
<div className="call-phone">
<form
name="contact-form"
method="post"
@gaurangrshah
gaurangrshah / docker-compose.yml
Last active August 8, 2019 05:43
Wordpress Docker Compose
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
@gaurangrshah
gaurangrshah / base_styles.scss
Created December 2, 2019 15:26
default-reset
@import '~bootstrap/scss/bootstrap.scss';
@import 'default.css';
/* Box sizing rules */
*,
*::before,
*::after {
box-sizing: border-box;
}
@gaurangrshah
gaurangrshah / useDebounce.js
Created December 14, 2019 21:42
react- useDebounce
import { useEffect, useRef, useState } from "react";
const useDebounce = (value, fn, duration) => {
const timeoutRef = useRef(setTimeout(() => undefined));
const [settled, setSettled] = useState(true);
const [numDebounces, setNumDebounces] = useState(-1);
useEffect(() => {
setNumDebounces((num: number) => num + 1);
if (numDebounces <= 0) return; // prevents initially unsettled output on component mount...
@gaurangrshah
gaurangrshah / useDebounce.js
Last active December 14, 2019 21:43
react- useDebounce
import { useEffect, useRef, useState } from "react";
const useDebounce = (value, fn, duration) => {
const timeoutRef = useRef(setTimeout(() => undefined));
const [settled, setSettled] = useState(true);
const [numDebounces, setNumDebounces] = useState(-1);
useEffect(() => {
setNumDebounces((num) => num + 1);
if (numDebounces <= 0) return; // prevents initially unsettled output on component mount...
@gaurangrshah
gaurangrshah / useEventListener.js
Created December 14, 2019 21:45
useFocus / EventListener
import { useEffect } from "react";
export default (target = window, type, listener, ...options) => {
// console.table({ target, type, ...options });
// console.log("useListener Ran", type, target);
useEffect(() => {
const targetIsRef = target.hasOwnProperty("current");
const currentTarget = targetIsRef ? target.current : target;
// console.debug("useListener Effect", currentTarget, targetIsRef);
if (currentTarget)
@gaurangrshah
gaurangrshah / useKeyPress.js
Last active December 14, 2019 21:47
useKeyPress
import { useState, useEffect } from "react";
export default function(targetKey, element = window, cb) {
const [keyPressed, setKeyPressed] = useState(false);
function downHandler(e) {
const { key } = e;
if (key === targetKey) {
setKeyPressed(true);
cb && cb()
@gaurangrshah
gaurangrshah / debounce.js
Last active August 13, 2021 05:10
Vanilla JS Utils
export function debounce(func, wait = 20, immediate = true) {
var timeout;
return function() {
var context = this,
args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;