JoshWComeau

Snippets

Short solutions to discrete problems which can be copied and pasted.

NameDescriptionCategoryLast Updated
VisuallyHidden
A convenient component for contextualizing visual content for screen readers
React ComponentJun 2024
range
Generate an array of numbers, for happy iteration
JavaScriptMar 2023
useMousePosition
Store the user's cursor position in React state
React HookMar 2022
useRetryUntilResolved
If at first you don't succeed, try try again.
React HookJan 2022
debounce
A classic debounce function, written in modern JS.
JavaScriptOct 2021
usePrefersReducedMotion
Use animations responsibly! Guard against unintended consequences with this accessible React hook.
React HookOct 2021
useRandomInterval
It's like setInterval, but more random!
React HookJul 2021
useTimeout
A React-friendly wrapper around the 'setTimeout' JavaScript method.
React HookJul 2021
useInterval
A React-friendly alternative to window.setInterval
React HookJul 2021
useStickyState
A modified “useState” hook that uses localStorage to remember state across sessions.
React HookJan 2021
useBoop
Apply a whimsical "temporary hover" effect with this customizable React hook.
React HookNov 2020
ShiftBy
Get ever-closer to pixel-perfection with this handy pixel-tweaking React component.
React ComponentNov 2020
InPortal
Convenient reusable portal component, for dropdowns and tooltips
React ComponentSep 2020
random
Generate a random number in a range. The way we all wish Math.random worked.
JavaScriptMay 2020
Scale with Pseudo-elements
A buttery hover effect that doesn't warp or distort your content
HTML & CSSMay 2020
useToggle
Handy syntactic sugar around React.useState, for toggling a boolean value on and off.
React HookMay 2020
HTML Skeleton
Bootstrap your next project with this batteries-included HTML starter.
HTML & CSSMay 2020
FadeIn
Fade stuff in on mount with this helpful utility component.
React ComponentMay 2020
useHasMounted
Avoid weird SSR issues with this handy React hook. Know whether you're rendering on the client or server!
React HookMay 2020