Skip to content

memoized-effect-dependencies

Experimental rule that flags effect dependencies the rule can tell are not memoized.

This rule checks dependency arrays passed to useEffect, useLayoutEffect, and useInsertionEffect. By default it uses the roblox-ts React environment and the definite mode.

In definite mode, it reports dependencies that are plainly unstable, such as inline objects, arrays, functions, classes, and new expressions. The stricter modes widen the net:

  1. definite Only report obviously unstable dependencies.
  2. moderate Also report unknown call results and values declared with non-const bindings.
  3. aggressive Report anything outside module scope unless the rule can tell it is stable.

The rule treats values from useMemo and useCallback as memoized. It also knows that useRef and useBinding return stable values, and that the second item from useState, useReducer, and useTransition is stable.

Incorrect
import { useEffect } from "@rbxts/react";
function Component() {
const dep = {}; // new object every render
useEffect(() => {}, [dep]);
}
Correct
import { useEffect, useMemo } from "@rbxts/react";
function Component() {
const dep = useMemo(() => ({}), []);
useEffect(() => {}, [dep]);
}
eslint.config.js
{
"cease-nonsense/memoized-effect-dependencies": [
"error",
{
"environment": "roblox-ts",
"mode": "definite",
"hooks": [
{ "name": "useEffect", "dependenciesIndex": 1 },
{ "name": "useLayoutEffect", "dependenciesIndex": 1 },
{ "name": "useInsertionEffect", "dependenciesIndex": 1 }
]
}
]
}

Add entries to hooks if you use custom effect-style hooks with a dependency array in a different argument position.