بنقرة واحدة
react-effects
Guidelines for when to use (and avoid) useEffect in React components
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Guidelines for when to use (and avoid) useEffect in React components
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to "dogfood", "QA", "exploratory test", "find issues", "bug hunt", "test this app/site/platform", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.
Run isolated mux desktop (Electron) instances (temp MUX_ROOT + free ports)
Run multiple isolated mux dev-server instances (temp MUX_ROOT + free ports)
Terminal-Bench integration for Mux agent benchmarking and failure analysis
Regenerate high-resolution README screenshots from Storybook stories. Use this skill when Chromatic detects visual diffs in any story under "Docs/README Screenshots", or when story data/layout changes require updated documentation assets. Triggers on: Chromatic visual regressions in readme screenshot stories, changes to App.readmeScreenshots.stories.tsx, changes to mockFactory.ts that affect screenshot stories, or explicit user request to update README images.
Guidelines for creating and managing Pull Requests in this repo
| name | react-effects |
| description | Guidelines for when to use (and avoid) useEffect in React components |
Primary reference: https://react.dev/learn/you-might-not-need-an-effect
Before adding useEffect, ask:
key prop instead// ❌ Derived state stored separately
const [fullName, setFullName] = useState('');
useEffect(() => setFullName(first + ' ' + last), [first, last]);
// ✅ Calculate during render
const fullName = first + ' ' + last;
// ❌ Event logic in effect
useEffect(() => { if (isOpen) doSomething(); }, [isOpen]);
// ✅ In the handler
const handleOpen = () => { setIsOpen(true); doSomething(); };
// ❌ Reset state on prop change
useEffect(() => { setComment(''); }, [userId]);
// ✅ Use key to reset
<Profile userId={userId} key={userId} />
For subscribing to external data stores (not DOM APIs), prefer useSyncExternalStore:
// ❌ Manual subscription in effect
const [isOnline, setIsOnline] = useState(true);
useEffect(() => {
const update = () => setIsOnline(navigator.onLine);
window.addEventListener('online', update);
window.addEventListener('offline', update);
return () => { /* cleanup */ };
}, []);
// ✅ Built-in hook for external stores
const isOnline = useSyncExternalStore(
subscribe,
() => navigator.onLine, // client
() => true // server
);
Always handle race conditions with an ignore flag:
useEffect(() => {
let ignore = false;
fetchData(query).then(result => {
if (!ignore) setData(result);
});
return () => { ignore = true; };
}, [query]);
For once-per-app-load logic (not once-per-mount), use a module-level guard:
let didInit = false;
function App() {
useEffect(() => {
if (!didInit) {
didInit = true;
loadDataFromLocalStorage();
checkAuthToken();
}
}, []);
}
Or run during module initialization (before render):
if (typeof window !== 'undefined') {
checkAuthToken();
loadDataFromLocalStorage();
}