All skills
siberiacancode avatar

/react-best-practices

@53c8ff5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

  • 77 files
  • 225.1 KB
  • MIT
  • Updated 4 months ago
  • GitHub

Use this Skill: https://skilld.dev/gh/siberiacancode/agent-skills/react-best-practices

This session only. Nothing lands on disk.

rulesjs-hoist-regexp.md

≈257 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Hoist RegExp Creation

Don't create RegExp inside render. Hoist to module scope or memoize with useMemo().

Incorrect (new RegExp every render):

function Highlighter({ text, query }: Props) {
  const regex = new RegExp(`(${query})`, 'gi')
  const parts = text.split(regex)
  return <>{parts.map((part, i) => ...)}</>
}

Correct (memoize or hoist):

const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

function Highlighter({ text, query }: Props) {
  const regex = useMemo(
    () => new RegExp(`(${escapeRegex(query)})`, 'gi'),
    [query]
  )
  const parts = text.split(regex)
  return <>{parts.map((part, i) => ...)}</>
}

Warning (global regex has mutable state):

Global regex (/g) has mutable lastIndex state:

const regex = /foo/g
regex.test('foo')  // true, lastIndex = 3
regex.test('foo')  // false, lastIndex = 0

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 53c8ff5. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 4 months ago
metadata
{
  "author": "vercel",
  "version": "1.0.0"
}

README badge

README badge for siberiacancode/agent-skills/react-best-practices