React / Next.js code snippets
Client and server components, hooks and route handlers. 30 free snippets, each with an explanation and usage notes.
- 30
- snippets
- 2
- types
All snippets
React / Next.js · UtilitiesWCAG contrast ratio functionCalculate the WCAG 2 contrast ratio between two hex colours, grade it AA or AAA and find the nearest passing shade.wcagcontrastaccessibility React / Next.js · ThemingTailwind shade scale generatorTurn one base colour into a 50 to 950 shade scale by mixing toward white and black in HSL, ready for Tailwind theme tokens.tailwindcolorpalette React / Next.js · UtilitiesRegex match highlighterSplit text into plain and matched segments for any regular expression, and render the matches as highlighted marks in React.regexhighlightreact React / Next.js · HooksVisibility-aware polling hookPoll an async function on an interval that pauses in hidden tabs, backs off on errors and cancels in-flight work on unmount.reactpollinghook React / Next.js · HooksSafe localStorage state hookA hydration-safe React hook that persists state in localStorage, survives blocked storage and syncs across browser tabs.reactlocalstoragehook React / Next.js · HooksUndo and redo history hookA reducer-based React hook that adds undo, redo, a history limit and coalesced updates to any piece of state.reactundo-redohistory React / Next.js · HooksDrag-and-drop file hookA small React hook that turns any element into a file drop zone with an accept filter and a stable dragging flag.reactdrag-dropfiles React / Next.js · HooksDrift-free countdown timer hookA React hook that counts down to a deadline using timestamps so it stays accurate through throttled tabs and pauses.reacttimercountdown React / Next.js · FormsSignature pad canvas componentA sharp, touch-friendly React signature pad using pointer events and smoothed curves, with clear and PNG export.reactcanvassignature React / Next.js · UtilitiesSandboxed iframe code playgroundA React HTML, CSS and JavaScript playground that runs user code in a sandboxed iframe with a debounced srcDoc update.reactiframesandbox React / Next.js · LayoutsPrint stylesheet for a resume pageA small React resume component with print CSS that sets A4 page margins, hides controls and avoids awkward page breaks.printcssresume React / Next.js · UtilitiesQR code component rendered as SVGA server-safe React component that turns text into a crisp QR code SVG with a quiet zone, colours and error correction.reactqr-codesvg React / Next.js · FormsMarkdown editor with live previewA two-pane React Markdown editor whose tiny escape-first renderer is safe against HTML injection and needs no packages.markdowneditorreact React / Next.js · FormsLine-items editor with live totalsA reducer-driven React table for adding, editing and removing line items with tax and total maths done in integer cents.reactformsinvoice React / Next.js · CardsKanban board with native drag and dropA library-free React kanban board using HTML5 drag events and a pure moveCard function to reorder across columns.reactkanbandrag-drop React / Next.js · UtilitiesCollapsible JSON tree viewerA recursive React component that renders any JSON value as an expandable tree with typed colours and item counts.reactjsontree React / Next.js · ChartsGantt bars from task datesConvert task start and end dates into percentage-based timeline bars with week gridlines in a small React component.gantttimelinedates React / Next.js · Feedback and empty statesCopy button with toast hookA React hook and button that copy text with a clipboard fallback and show a self-dismissing confirmation toast.reactclipboardtoast React / Next.js · HooksPan and zoom surface hookA React hook that adds wheel zoom around the cursor, drag panning and a CSS transform to any large canvas or diagram.reactpanzoom React / Next.js · APIsSSRF-safe fetch for NodeFetch user-supplied URLs from a server route while blocking private addresses, pinning DNS, limiting redirects, time and size.ssrfsecuritynode React / Next.js · ChartsMind map auto layoutPosition a tree of ideas automatically with a subtree-height layout and render it as curved SVG connectors in React.mind-maptree-layoutsvg React / Next.js · UtilitiesLCS text diff with a React rendererCompute a line-by-line diff using the longest common subsequence and render additions and deletions in a React view.difflcstext React / Next.js · UtilitiesGenerate an invoice PDF in the browserBuild and download a paginated invoice PDF client-side with jsPDF, using a lazy import and manual table layout.pdfjspdfinvoice React / Next.js · UtilitiesEMI and amortisation scheduleCalculate a fixed monthly instalment and a full month-by-month principal and interest schedule that ends exactly at zero.loanemifinance