/react-effect-event:react-effect-eventfrom react-effect-event
Use React's useEffectEvent to separate reactive dependencies from non-reactive "latest value" reads inside Effects. Apply when writing or reviewing any useEffect whose dependency array is fighting you: stale closures, an effect that re-runs (re-subscribes / reconnects / restarts a timer) more than it should, an eslint-disable-next-line react-hooks/exhaustive-deps, a value read inside an event callback or interval that you do NOT want to trigger re-synchronization, or a ref used purely to dodge a dependency. Stack: React 19.2+ (useEffectEvent is stable, imported from 'react'), React Native / Expo.
Ships in react-effect-event. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
useEffectEvent lets an Effect read the latest props/state without listing them
as dependencies, so the Effect re-runs only when its truly reactive inputs change.
It is the correct tool for the recurring tension in this codebase: an Effect that
sets up a subscription / listener / interval, but whose callback also reads values
that should NOT cause it to tear down and re-set-up.
Reach for this skill when you see — or are about to write — any of these:
addEventListener is
removed and re-added, a setInterval restarts, an audio/video subscription is
torn down, just because a value read inside the callback changed.// eslint-disable-next-line react-hooks/exhaustive-deps used to silence a
warning about a value the author deliberately wants to read fresh but not react to.useRef whose only job is to smuggle the latest prop/state into an Effect or
listener so it doesn't appear in the dependency array (fooRef.current = foo).If none of these apply — if the Effect simply needs to re-synchronize when a value
changes — do not introduce useEffectEvent. Plain dependencies are correct.
Inside an Effect, split every value you read into two buckets:
roomId for a
connection, url for a subscription, delay for an interval). → keep in deps.theme, muted, the current volume,
an onChange handler from props, the latest position). → move the logic that
reads it into an Effect Event.Decision rule: "If this value changes, should the subscription / listener / timer be torn down and recreated?" Yes → dependency. No → Effect Event.
import { useEffect, useEffectEvent } from "react";
function ChatRoom({ roomId, theme }: { roomId: string; theme: Theme }) {
// Non-reactive logic: reads latest `theme`, but theme changes must NOT reconnect.
const onConnected = useEffectEvent(() => {
showNotification("Connected!", theme);
});
useEffect(() => {
const connection = createConnection(roomId);
connection.on("connected", () => onConnected());
connection.connect();
return () => connection.disconnect();
}, [roomId]); // ✅ only roomId. No theme. No eslint-disable. No lint warning.
}
The lint rule (eslint-plugin-react-hooks) understands useEffectEvent and will
not demand the Effect Event or the values it reads in the dependency array.
onPress), never pass it as a prop to a child
component or into another Hook. For those cases use a normal function or
useCallback.useEffectEvent is NOT a tool to empty the
dependency array or silence exhaustive-deps wholesale. Only the genuinely
non-reactive event-like logic moves into it; reactive deps stay listed. Misusing
it this way hides real bugs.useCallback.Replace a "latest value" ref smuggled into a listener
// ❌ Before: ref exists only to dodge the dependency array
const volumeRef = useRef(volume);
volumeRef.current = volume;
useEffect(() => {
const sub = player.addListener("tick", () => applyVolume(volumeRef.current));
return () => sub.remove();
}, []); // lint: silenced or lying
// ✅ After
const onTick = useEffectEvent(() => applyVolume(volume));
useEffect(() => {
const sub = player.addListener("tick", () => onTick());
return () => sub.remove();
}, [player]); // honest deps; no ref, no disable
Interval that reads latest state without restarting
const onTick = useEffectEvent(() => setCount(count + increment));
useEffect(() => {
const id = setInterval(() => onTick(), 1000);
return () => clearInterval(id);
}, []); // ✅ timer is NOT recreated when count/increment change
Effect that reconnects on roomId but notifies using non-reactive muted/theme
const onConnected = useEffectEvent((id: string) => {
if (!muted) showNotification("Connected to " + id, theme);
});
useEffect(() => {
const connection = createConnection(roomId);
connection.on("connected", () => onConnected(roomId));
connection.connect();
return () => connection.disconnect();
}, [roomId]); // ✅ reconnect on roomId only — not on muted or theme
When writing or reviewing an Effect, confirm:
exhaustive-deps disable or dependency-dodging ref is reconsidered — could an
Effect Event remove the need for it?useEffectEvent is declared at top level and called only from Effects.Official docs: https://react.dev/reference/react/useEffectEvent Background — "Separating Events from Effects": https://react.dev/learn/separating-events-from-effects
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub thedv91/coding-skills --plugin react-effect-event