Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
@srph
srph / readme.md
Created July 22, 2026 18:36
React: useAnimationText - Rotating text for long-running pending buttons

what

Rotating text for long-running pending buttons

usage

const STOP_TEXTS = [
  "Closing Positions",
  "Canceling Orders",
  "Finalizing Trades",
 "Updating Balances",
@srph
srph / readme.md
Last active July 22, 2026 18:38
Next: useUnsavedChanges - A super basic boilerplate wrapping Next.js route abort events

what

A super basic boilerplate wrapping Next.js route abort events

usage

useUnsavedChangesWarning(form.isDirty === true && status !== 'pending')
@srph
srph / layer-card.tsx
Last active July 22, 2026 18:38
layer-card - modern duo-tone cards
import type { HTMLAttributes } from "react";
import { cn } from "@/lib/cn";
// Example: <LayerCard><LayerCardSecondary>Title</LayerCardSecondary><LayerCardContent>Content</LayerCardContent></LayerCard>
export function LayerCard({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn(
"rounded-lg border border-neutral-200 bg-neutral-100",
className,
@srph
srph / readme.md
Last active July 22, 2026 18:37
React: useLatestMutationState - An ergonomic wrapper for react-query's useMutationState

what

An ergonomic wrapper for react-query's useMutationState

usage

export function useCreatePostMutation(...) {
  return useMutation({ mutationKey: ['create-post'], ... })
}

export function useCreatePostMutationState(...) {
@srph
srph / readme.md
Last active July 22, 2026 18:38
React: useEphemeralState - Latches a boolean flag for a short duration, then resets to `false`

what

Latches a boolean flag for a short duration, then resets to false

Useful for when an action succeeds, then you want to reset back to normal after a short while

User completes swapping X to Y: temporarily show "Success" then allow user to interact with the form again

usage

const { mutate, status } = useMutation(...)
@srph
srph / readme.md
Last active July 22, 2026 18:38
React: useWiggle - Wiggle relevant elements when the user does the wrong thing twice

what

Wiggle relevant elements when the user does the wrong thing twice (e.g. submitting a form with validation errors twice)

usage

const { scope: wiggleRef, wiggle } = useWiggle();

const handleSubmit = () => {
  if (errors) {
 wiggle();
@srph
srph / readme.md
Last active January 9, 2025 06:12
React: Flash success state before reverting back to normal state

Usage

Here's an example of using this hook on top of react-query.

When your react-query mutation succeeds, we'll only flash the success state for 3 seconds until it's reverted back to normal

const isSuccess = useEphemeralState(
  mutation.isSuccess,
  3000,
);
@srph
srph / readme.md
Created October 7, 2024 05:51
Vercel Deploy Script

Vercel Deploy Script

This takes advantage of deployment hooks on Vercel. This simply removes the deploy file if it exists. Otherwise, it creates it. Then pushes it to the repository.

Usage

Add to your package.json

{
@srph
srph / index.ts
Last active July 17, 2024 13:59
JS/TS: Multiply BigInt to Float
// Bn -> Float multiplication works like this: 150e6 * (0.5 * 100) / 100
// Also does some coercions for readability
const multiplyBnToFloat = (a: string, b: string) => {
return (BigInt(a) * BigInt(Number(b) * 100)) / BigInt(100)
}
// 75000000
multiplyBnToFloat('150000000', '0.5000000000')
@srph
srph / 0rc.code-snippets
Last active May 30, 2024 19:18
React Component Snippet for VS Code (based on filename, with prop types)
{
"React Component": {
"prefix": "0rc",
"body": [
"import React from 'react';",
"",
"interface ${TM_FILENAME_BASE}Props {",
" name: string;",
"}",
"",