All skills
sergiodxa avatar

/frontend-react-best-practices

@734526d

React performance optimization guidelines. Use when writing, reviewing, or refactoring React components to ensure optimal rendering and bundle patterns. Triggers on tasks involving React components, hooks, memoization, or bundle optimization.

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

This session only. Nothing lands on disk.

rulesrerender-move-effect-to-event.md

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

Put Interaction Logic in Event Handlers

If a side effect is triggered by a specific user action (submit, click, drag), run it in that event handler. Do not model the action as state + effect; it makes effects re-run on unrelated changes and can duplicate the action.

Incorrect (event modeled as state + effect):

function Form() {
  let [submitted, setSubmitted] = useState(false);
  let theme = useContext(ThemeContext);

  useEffect(() => {
    if (submitted) {
      post("/api/register");
      showToast("Registered", theme);
    }
  }, [submitted, theme]);

  return <button onClick={() => setSubmitted(true)}>Submit</button>;
}

Correct (do it in the handler):

function Form() {
  let theme = useContext(ThemeContext);

  function handleSubmit() {
    post("/api/register");
    showToast("Registered", theme);
  }

  return <button onClick={handleSubmit}>Submit</button>;
}

Reference: Should this code move to an event handler?

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill is a collection of React performance and composition guidelines. It contains no executable code, scripts, or malicious patterns and is entirely informational.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    37/37 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

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

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-react-best-practices