Skip to content

Instantly share code, notes, and snippets.

@erictherobot
erictherobot / useDocument.ts
Last active February 21, 2022 21:19
Firebase / Firestore version 9 SDK useDocument React Hook
import { useEffect, useState } from 'react';
import { doc, getDoc, DocumentData } from 'firebase/firestore';
import { db } from '@/lib/firebase';
export function useDocument(collection: string, id: string, callback?: any) {
const [data, setData] = useState<DocumentData | undefined>(undefined);
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<any>(null);
useEffect(() => {
@erictherobot
erictherobot / usePrevious.ts
Created April 30, 2021 14:26
Get Previous Hook
import { useRef, useEffect } from 'react';
export function usePrevious(value: any) {
const ref = useRef();
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
@erictherobot
erictherobot / useWindowSize.ts
Created April 30, 2021 14:25
Window Size Hook
import { useScreen } from '@/hooks/useScreen';
interface WindowSize {
width: number;
height: number;
}
export function useWindowSize(): WindowSize {
const screen = useScreen();
@erictherobot
erictherobot / useScreen.ts
Created April 30, 2021 14:24
Screen Width & Height Hook
import { useState, useEffect } from 'react';
export function useScreen() {
const getScreen = () => {
if (typeof window !== 'undefined') {
return window.screen;
}
return undefined;
};
@erictherobot
erictherobot / heart.json
Created September 17, 2018 17:27
heart.json
{"v":"4.6.6","fr":25,"ip":0,"op":22,"w":148,"h":148,"nm":"2.0 A-首页-inline播放","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"形状图层 1","ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[74,74,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[25,25,100]}},"ao":0,"shapes":[{"d":1,"ty":"el","s":{"a":1,"k":[{"i":{"x":[0.667,0.667],"y":[1,1]},"o":{"x":[0.333,0.333],"y":[0,0]},"n":["0p667_1_0p333_0","0p667_1_0p333_0"],"t":2,"s":[0,0],"e":[29,29]},{"i":{"x":[0.667,0.667],"y":[1,1]},"o":{"x":[0.333,0.333],"y":[0,0]},"n":["0p667_1_0p333_0","0p667_1_0p333_0"],"t":7,"s":[29,29],"e":[0,0]},{"t":16}]},"p":{"a":1,"k":[{"i":{"x":0.52,"y":1},"o":{"x":0.6,"y":0},"n":"0p52_1_0p6_0","t":1,"s":[0,0],"e":[0,189],"to":[0,31.5],"ti":[0,-40]},{"i":{"x":0.38,"y":1},"o":{"x":0.333,"y":0},"n":"0p38_1_0p333_0","t":6,"s":[0,189],"e":[0,240],"to":[0,40],"ti":[0,-8.5]},{"t":15}]},"nm":"椭圆路径 1","mn":"ADBE Vector Shape - Ellipse"},{"ty":"fl","c":{"a":0,"k":[1,0.1921569,0.2666667,1]},"o":{"a":0,"k":100},"r":1,"nm":"填充 1","mn":"AD
@erictherobot
erictherobot / gist:0963b08a3d3383183b83593f06e19e1c
Created March 25, 2018 18:34
Government Contracting Acronyms
8(a) Section 8 (a) of the Small Business Act; Federal Contracting Preference Program for Disadvantaged Businesses
AAR After Action Report
ACAT Acquisition Category
ACO Administrative Contracting Officer
ACQ Acquisition
ACS Assistant Chief of Staff
ACWP Actual Cost of Work Performed
ADA Americans with Disabilities Act
ADPE Automated Data Processing Equipment
const withSass = require('@zeit/next-sass')
module.exports = withSass()
const withTs = require('next-typescript');
module.exports = withTs({ /* additional config*/ })
module.exports = {
webpack(config, options) {
const { dir, defaultLoaders } = options
config.resolve.extensions.push('.ts', '.tsx')
config.module.rules.push({
test: /\.+(ts|tsx)$/,
include: [dir],
exclude: /node_modules/,
use: [
defaultLoaders.babel,
@erictherobot
erictherobot / gist:6ea2d2e663d7bd081269daf843adaec3
Created November 24, 2017 16:35
Fixes Definition for rule 'jsx-a11y/href-no-hash' was not found (jsx-a11y/href-no-hash)
(
export PKG=eslint-config-airbnb;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)