Skip to content

no-new-instance-in-use-memo

errorReact

Reports configured new expressions inside useMemo callbacks, including traced local helper calls.

By default, the rule reports new Instance(...) inside useMemo. It also follows local helper functions called from the memo callback, up to maxHelperTraceDepth, so a helper that creates an instance is still reported.

The rule only checks useMemo imported from the configured React environment. environment: "roblox-ts" watches @rbxts/react, and environment: "standard" watches react.

Incorrect
import { useMemo } from "@rbxts/react";
const model = useMemo(() => {
return new Instance("Model");
}, []);
Also incorrect
import { useMemo } from "@rbxts/react";
function createModel() {
return new Instance("Model");
}
const model = useMemo(() => createModel(), []);
Correct
import { useMemo } from "@rbxts/react";
const model = new Instance("Model");
const memoizedModel = useMemo(() => model, []);
Option Type Default Notes
constructors string[] ["Instance"] Constructor names to report.
environment "roblox-ts" | "standard" "roblox-ts" Picks @rbxts/react or react imports.
maxHelperTraceDepth integer 4 Helper-call depth to trace from the memo callback. 0 disables helper tracing.
import ceaseNonsense from "@pobammer-ts/eslint-cease-nonsense-rules";
export default [
{
plugins: {
"cease-nonsense": ceaseNonsense,
},
rules: {
"cease-nonsense/no-new-instance-in-use-memo": [
"error",
{
constructors: ["Instance", "Vector3"],
environment: "roblox-ts",
maxHelperTraceDepth: 2,
},
],
},
},
];