prototype
MAmattpocock/skills336k近 7 天新增 5,004 个 star
Combine React's official "You Might Not Need an Effect" guidance with this project's stricter no direct useEffect stance. Use when writing, reviewing, or refactoring React components that might reach for useEffect, derived state, event relays, reset logic, subscriptions, or client fetching.
Default rule for this project: do not reach for direct useEffect first.
Most effect usage in React code is a sign that the component is syncing state that should be derived during render, routing an event through state, or resetting local state in a way React already models better.
This skill merges:
useEffect preferenceBefore writing any effect, ask these in order:
keyuseMemouseSyncExternalStore or a focused custom hookIf you answer yes to any of 1 through 5, do not write a direct useEffect.
React allows effects for real external synchronization. This project is stricter:
useEffect in components whenever a clearer pattern existskey remounts, memoization, query libraries, Convex hooks, and focused custom hooksuseMountEffect wrapper instead of sprinkling raw useEffect through feature codeExample wrapper:
import { useEffect } from "react";
export function useMountEffect(effect: () => void | (() => void)) {
useEffect(effect, []);
}
Use that only for one time external setup like DOM focus, third party widgets, or browser API listeners that belong to the component lifecycle.
Bad smell:
useEffect(() => setX(deriveFromY(y)), [y])Do this instead:
function TodoList({ todos, showActive }: Props) {
const activeTodos = todos.filter((todo) => !todo.completed);
const visibleTodos = showActive ? activeTodos : todos;
return <List items={visibleTodos} />;
}
If it can be calculated from existing inputs, keep it out of state.
useMemoIf the calculation is pure and expensive, memoize it instead of syncing it into state:
const visibleTodos = useMemo(
() => getVisibleTodos(todos, showActive),
[todos, showActive],
);
Use memoization only when there is real repeated work to skip.
Bad smell:
Do this instead:
function PurchaseButton({ product }: Props) {
async function handleClick() {
await addToCart(product);
showNotification(`Added ${product.name}`);
}
return <button onClick={handleClick}>Buy</button>;
}
If the work happens because the user clicked, submitted, dragged, or selected, keep it in the handler.
key, not effect choreographyBad smell:
useEffect(() => setFormState(initialFromProps), [id])Do this instead:
function EditContact({ contact, onSave }: Props) {
return <EditContactForm key={contact.id} contact={contact} onSave={onSave} />;
}
If a different entity should feel like a fresh component instance, give the inner component a key.
If you cannot derive it and do not want a full remount, adjust the state during render of the same component before children render stale data.
Prefer these, in order:
keyBad smell:
fetch(...).then(setState) inside a component effectPreferred options:
Example custom hook pattern:
function useSearchResults(url: string) {
const [data, setData] = useState<Result[] | null>(null);
useEffect(() => {
let ignore = false;
fetch(url)
.then((response) => response.json())
.then((json) => {
if (!ignore) {
setData(json);
}
});
return () => {
ignore = true;
};
}, [url]);
return data;
}
That is still less preferred than a dedicated query layer, but better than scattering raw fetch effects across components.
useSyncExternalStoreFor browser or third party stores, prefer the React built in subscription model:
function useOnlineStatus() {
return useSyncExternalStore(
subscribe,
() => navigator.onLine,
() => true,
);
}
This is clearer and safer than mirroring an external mutable source through ad hoc effect code.
An effect or useMountEffect is appropriate when the component must synchronize with something outside React:
When you use one, document the external system in a comment or nearby helper.
If you are about to write useEffect, check:
keyuseSyncExternalStoreIf you cannot name the external system, you probably do not need an effect.
Use these during review:
key={entityId} remove the reset logic entirelyThe safest path in this repo is simple:
keySources:
MAmattpocock/skills336k近 7 天新增 5,004 个 star
AFaffaan-m/ECC314k近 7 天新增 4,125 个 star
FIfirecrawl/firecrawl214k近 7 天新增 5,821 个 star
ANanthropics/skills203k近 7 天新增 3,333 个 star
用 React、Tailwind 和 shadcn/ui 构建多组件页面。
ANanthropics/skills203k近 7 天新增 3,333 个 star