no-new-instance-in-use-memo
Reports configured new expressions inside useMemo callbacks, including traced local helper calls.
Rule details Problem
Section titled “Rule details ”ProblemBy 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.
Examples
Section titled “Examples” Incorrect
Constructor inside useMemo
Section titled “Constructor inside useMemo”import { useMemo } from "@rbxts/react";
const model = useMemo(() => { return new Instance("Model");}, []); Also incorrect
Helper traced from useMemo
Section titled “Helper traced from useMemo”import { useMemo } from "@rbxts/react";
function createModel() { return new Instance("Model");}
const model = useMemo(() => createModel(), []); Correct
Reuse or create outside the memo callback
Section titled “Reuse or create outside the memo callback”import { useMemo } from "@rbxts/react";
const model = new Instance("Model");
const memoizedModel = useMemo(() => model, []);Options
Section titled “Options”| 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 "eslint-plugin-cease-nonsense";
export default [ { plugins: { "cease-nonsense": ceaseNonsense, }, rules: { "cease-nonsense/no-new-instance-in-use-memo": [ "error", { constructors: ["Instance", "Vector3"], environment: "roblox-ts", maxHelperTraceDepth: 2, }, ], }, },];Related rules
Section titled “Related rules” no-unused-use-memo Disallows useMemo calls that are only used for side effects
no-useless-use-effect Reports effects that are not syncing with anything external