mcpField
R
react-useeffect-avoid

react-useeffect-avoid

github.com/flpbaladaDevelopment28138 installsUpdated 13w ago
Repository

About react-useeffect-avoid

A React development skill explaining when to avoid `useEffect` and which patterns to use instead. It distinguishes external-system synchronization from ordinary application logic.

Key features

  1. 01Decision tree for `useEffect`
  2. 02Alternatives for derived state and events
  3. 03Guidance on external-system effects
  4. 04React 19 resource-reading example

Use cases

  1. 01Reviewing effects used for derived state
  2. 02Choosing an event handler for user actions
  3. 03Deciding whether an effect is needed for an integration

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/flpbalada/my-opencode-config --skill react-useeffect-avoid

After installing, type/react-useeffect-avoidin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

context/
anti-patterns.md
decision-tree.md
patterns-to-avoid.md

Details

From the project README

React: When Not to Use useEffect

Core Principle

useEffect is an escape hatch for synchronizing with external systems, not a general-purpose tool for state management or event handling.

Modern React patterns prioritize one-way data flow and event-driven updates over effect-based synchronization to avoid performance penalties and complex synchronization bugs.

Decision Tree

Need to sync with external system?
├─ Yes (browser APIs, websockets, timers)
│  └─ Use useEffect
│
└─ No (pure React application logic)
   ├─ Derived state calculation?
   │  ├─ Yes → Calculate during render
   │  └─ No → Continue...
   │
   ├─ User action triggered?
   │  ├─ Yes → Use event handler
   │  └─ No → Continue...
   │
   ├─ State reset needed?
   │  ├─ Yes → Use key prop
   │  └─ No → Continue...
   │
   └─ Really need effect after re-think?
      └─ Yes → Use useState/useReducer/setState pattern

Quick Reference

❌ Don't use useEffect for:
ScenarioProblemAlternative
Derived stateDouble renderCalculate during render
State resetsStale dataUse key prop
User actionsLost intentEvent handlers
List filteringExtra rendersFilter in render
Browser APIsTearing bugs (concurrent)useSyncExternalStore
Form submissionFragile flag patternDirect async handler
Data fetchingManual cache managementReact Query, SWR, Suspense
✅ DO use useEffect for:
  • Subscribing to external systems (websockets, browser APIs, etc.)
  • Setting up timers with cleanup
  • Managing third-party library integration
  • Document title changes
  • Analytics/telemetry when rendering completes

React 19: New Alternatives

// React 19+ - Direct resource reading
function UserProfile({ userId }) {
  const user = use(fetchUser(userId)); // Reads promise directly
  return <div>{user.name}</div>;
}

Progressive Disclosure

TopicFileWhen to Use
Anti-patterns with examplescontext/anti-patterns.mdDetailed code examples of useEffect mistakes
Patterns to always avoidcontext/patterns-to-avoid.mdCommon anti-patterns like logging, DOM manipulation
Decision tree & referencescontext/decision-tree.mdQuick lookup and further reading

References

Comments

Markdown supported