Skip to content

Instantly share code, notes, and snippets.

View BenGladman's full-sized avatar

Ben Gladman BenGladman

View GitHub Profile
@BenGladman
BenGladman / .bashrc
Last active August 21, 2021 21:43
shell config
stty -ixon # allow ctrl-s for search
HISTCONTROL=ignoredups:erasedups # no duplicate entries
HISTSIZE=100000 # big big history
HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
@BenGladman
BenGladman / themedStyledComponents.ts
Created March 9, 2020 17:08
Styled components exported with theme shape
import * as styledComponents from "styled-components";
import { ThemedStyledComponentsModule } from "styled-components";
import { Theme } from "./theme";
const {
default: styled,
css,
createGlobalStyle,
keyframes,
@BenGladman
BenGladman / useClickAway.ts
Created March 9, 2020 17:04
Hook to trigger callback on clicking away from element
import { RefObject, useEffect, useRef } from "react";
/**
* Run handler on mouse down in the document on any element *not* contained in the specified elements
*/
export function useClickAway(
onClickAway?: (event: UIEvent) => void,
...elements: (RefObject<HTMLElement> | HTMLElement | null | undefined)[]
) {
// hold elements array in a ref so don't need to include in the useEffect deps
@BenGladman
BenGladman / usePopper.ts
Last active March 9, 2020 17:05
Hook to use Popper.js
/**
* Adapted from https://github.com/react-bootstrap/react-overlays/blob/master/src/usePopper.js
*/
import {
Instance,
Modifier,
Options,
Placement,
popperGenerator,
@BenGladman
BenGladman / useCombinedRefs.ts
Last active March 9, 2020 17:05
Hook to combine refs into a single ref
import React, { useCallback, useRef } from "react";
export function useCombinedRefs<T>(
...refs: Array<React.Ref<T> | undefined>
): (instance: T | null) => void {
// save the current refs array in a local ref so the returned callback is stable
const refsRef = useRef(refs);
refsRef.current = refs;
return useCallback(instance => {