.mux/skills/react-effects/SKILL.md
Guidelines for when to use (and avoid) useEffect in React components
npx skillsauth add coder/mux react-effectsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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();
}
testing
Testing doctrine, commands, and test layout conventions
data-ai
Terminal-Bench integration for Mux agent benchmarking and failure analysis
documentation
Guidelines for creating and managing Pull Requests in this repo
tools
Connects Mux mobile (Expo web/native) to an isolated dev-server sandbox with deterministic port setup, backend pairing, and Chrome MCP interaction. Use when implementing or validating mobile features against a sandboxed Mux backend.