memoized-effect-dependencies
Experimental rule that flags effect dependencies the rule can tell are not memoized.
Rule details Experimental
Section titled “Rule details ”ExperimentalThis 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:
- definite Only report obviously unstable dependencies.
- moderate Also report unknown call results and values declared with non-
constbindings. - 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.
Examples
Section titled “Examples”Unmemoized dependencies
Section titled “Unmemoized dependencies”import { useEffect } from "@rbxts/react";
function Component() { const dep = {}; // new object every render useEffect(() => {}, [dep]);}Memoized dependencies
Section titled “Memoized dependencies”import { useEffect, useMemo } from "@rbxts/react";
function Component() { const dep = useMemo(() => ({}), []); useEffect(() => {}, [dep]);}Configuration
Section titled “Configuration”{ "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.