Skip to content

Instantly share code, notes, and snippets.

View jamstooks's full-sized avatar
🐶

Benjamin W Stookey jamstooks

🐶
  • Bellingham, WA
View GitHub Profile
@jamstooks
jamstooks / useRect.js
Last active July 23, 2019 20:07
Hook to get a bounding rect object for a specific, referenced DOM object
import { useEffect, useState } from 'react'
/**
* makes a `rect` object available to a component based on the
* dimensions of DOM object using a reference
*
* Usage:
* const MyComponent = (props) => {
* const _ref = useRef(null)
* const rect = useRect(_ref)
@jamstooks
jamstooks / caching.js
Created August 10, 2020 20:05
Cache a function result in SessionStorage (no matter the properties)
import _ from 'lodash';
/**
* Wraps a function to cache the result
* no matter what props are passed
* only caches the result if it isn't empty
*
* This is just using a closure for caching.
* If the function is declared again, the value will be lost.
*/
@jamstooks
jamstooks / react-rules-of-thumb.md
Last active March 9, 2022 18:59
React Rules of Thumb

Rules of Thumb

For React Applications and Others

Brevity, but not at the expense of clarity

Consistency, but not at the expense of improvement

Less Markup

@jamstooks
jamstooks / machine.js
Last active May 24, 2022 21:37
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions