Files
famapp/.agents/skills/react-best-practices/rules/rerender-defer-reads.md
T
ginnoir 3d825fba20
CI / checks (push) Successful in 1m51s
CI / build (push) Successful in 3m34s
chore: vendor react-best-practices agent skill for cursor agents
Adds the Vercel skill under .agents with famapp path patterns.

Includes skills-lock.json pin.
2026-07-03 03:33:57 -05:00

983 B

title, impact, impactDescription, tags
title impact impactDescription tags
Defer State Reads to Usage Point MEDIUM avoids unnecessary subscriptions rerender, searchParams, localStorage, optimization

Defer State Reads to Usage Point

Don't subscribe to dynamic state (searchParams, localStorage) if you only read it inside callbacks.

Incorrect (subscribes to all searchParams changes):

function ShareButton({ chatId }: { chatId: string }) {
  const searchParams = useSearchParams();

  const handleShare = () => {
    const ref = searchParams.get("ref");
    shareChat(chatId, { ref });
  };

  return <button onClick={handleShare}>Share</button>;
}

Correct (reads on demand, no subscription):

function ShareButton({ chatId }: { chatId: string }) {
  const handleShare = () => {
    const params = new URLSearchParams(window.location.search);
    const ref = params.get("ref");
    shareChat(chatId, { ref });
  };

  return <button onClick={handleShare}>Share</button>;
}