clean-react-hooks
Use when writing, fixing, editing, or refactoring React hooks, custom hooks, useEffect, dependency arrays, stale closures, subscriptions, refs, or memoization.
Works with
---
name: clean-react-hooks
description: Use when writing, fixing, editing, or refactoring React hooks, custom hooks, useEffect, dependency arrays, stale closures, subscriptions, refs, or memoization.
license: MIT
---
# Clean Hooks
Hooks should make stateful behavior explicit. Effects are for synchronization with systems outside React, not for deriving ordinary render data.
## R4: Effects
Use `useEffect` for:
- Subscriptions and cleanup
- Browser APIs and imperative widgets
- Network calls when the project does not use a data-fetching library
- Synchronizing React state with an external system
Do not use `useEffect` for values that can be computed during render.
```tsx
// Bad - derived state via effect
const [fullName, setFullName] = useState("");
useEffect(() => {
setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);
// Good - derived during render
const fullName = `${firstName} ${lastName}`;
```
## Dependencies
- Treat the dependency array as a correctness contract.
- Do not suppress exhaustive-deps without explaining the external invariant.
- Stabilize callbacks only when identity matters to a child, subscription, or memoized computation.
- Prefer moving logic inside the effect over hiding dependencies.
## R8: Custom Hooks
Create a custom hook when behavior is reusable and stateful, or when it gives a complex effect a clear boundary.
```tsx
function useWindowSize(): WindowSize {
const [size, setSize] = useState(getWindowSize);
useEffect(() => {
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
function handleResize() {
setSize(getWindowSize());
}
}, []);
return size;
}
```
Keep hook APIs small. Return named objects for multiple values unless tuple ordering is a local convention.
## Refs
Use refs for imperative handles, DOM nodes, and mutable values that should not trigger render. Do not use refs to sidestep normal state flow.
## Common Mistakes
- Using effects to copy props into state.
- Adding empty dependency arrays to "run once" while reading changing values.
- Using `useMemo` or `useCallback` everywhere without a measured reason.
- Returning unstable object shapes from hooks that consumers put into dependency arrays.More Git Workflows skills
git-commit
github/awesome-copilot
Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping
git-workflow-and-versioning
addyosmani/agent-skills
Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.
resolve-merge-conflicts
warpdotdev/common-skills
Resolve Git merge conflicts by extracting only unresolved paths, conflict hunks, and compact diffs instead of loading whole files into context. Use when a merge, rebase, cherry-pick, or stash pop stops on conflicts, when `git status` shows unmerged paths, or when files contain conflict markers.

