Files
famapp/.agents/skills/react-best-practices/upstream/rules/advanced-init-once.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

967 B

title, impact, impactDescription, tags
title impact impactDescription tags
Initialize App Once, Not Per Mount LOW-MEDIUM avoids duplicate init in development initialization, useEffect, app-startup, side-effects

Initialize App Once, Not Per Mount

Do not put app-wide initialization that must run once per app load inside useEffect([]) of a component. Components can remount and effects will re-run. Use a module-level guard or top-level init in the entry module instead.

Incorrect (runs twice in dev, re-runs on remount):

function Comp() {
  useEffect(() => {
    loadFromStorage();
    checkAuthToken();
  }, []);

  // ...
}

Correct (once per app load):

let didInit = false;

function Comp() {
  useEffect(() => {
    if (didInit) return;
    didInit = true;
    loadFromStorage();
    checkAuthToken();
  }, []);

  // ...
}

Reference: Initializing the application