Snippets

Inspired by Josh W. Comeau's snippets, this is a collection of code snippets I've made over the years that you can look at for inspiration or copy/paste at will.

clamp()Description: A function that "clamps" a number between a minimum and maximum valueCategory: JavaScript
compose() & pipe()Description: Functions for composing other functionsCategory: JavaScript
indexByKey()Description: A function to turn an array of objects into an object, indexed by the chosen keyCategory: JavaScript
inflect()Description: Function used to choose the correct form of a word, singular or pluralCategory: JavaScript
MarginDescription: A component for easily applying margins with component compositionCategory: React Component
partition()Description: Split an array with a predicate filterCategory: JavaScript
randomRGB()Description: Function to generate random rgb() stringsCategory: JavaScript
React Native Layout componentsDescription: Copy/pasteable layout components for React NativeCategory: React Native
ShiftByDescription: A component for compositionally adjusting an element to pixel perfect alignmentCategory: Astro
toArray()Description: A function for normalizing a value to an arrayCategory: JavaScript
useAsyncSafeState()Description: Hook for async state that automatically prevents memory leaksCategory: React Hooks
useBool()Description: A basic React Hook for managing binary statesCategory: React Hooks
useForceUpdate()Description: An imperative way to force a component to update with HooksCategory: React Hooks
useLocalStorage()Description: Hook for persisting state to localStorageCategory: React Hooks
usePrevious()Description: Hook for storing and getting a previous valueCategory: React Hooks
Logo for Data Structures and Algorithms
Data Structures and Algorithms
Check out my courses!
If you enjoy my posts, you might enjoy my courses, too. Click the button to view the course or go to Courses for more information.
Sign up for my newsletter
Let's chat some more about TypeScript, React, and frontend web development. Unsubscribe at any time.