What it flags
AuseState value is changed in place (push, splice, sort, reverse, an assignment to a property or index) and then passed to its own setter. React compares by reference, so the re-render is skipped. The change is also seen through type and non-null assertions and bracket calls with a literal method name, such as items.
The rule prefers silence when it cannot tell what ran:
-
A change to a value read through a getter, as in
items.rows.push(row)whererowsis declared withget, is not reported: the getter may return a new value on every read. A getter in an object literal whose only statement returns a plain property of the same object, such asreturn this.stored, is read through. -
A
??=,||=or&&=is skipped only when the initial object literal and every use of the state and its setter show that it cannot assign. A declared or asserted type is not enough. Reading that same property keeps the proof; any other use of the state, such as rendering a different property or passing the state to a function, ends it.??=on the state’slengthis also skipped when the initial value is an array literal or a built-innew Array(), which own theirlength, and the setter is only given the state back. A built-in typed array inherits itslength, so there every use of the state must pass the same proof, where reading an element such asitems[0]also keeps it. -
A method that the file assigns on a binding or its
constalias, as inwork.forEach = later, is not treated as built in, even when the receiver is typed. AMaporSetmethod counts only when the default library declares it, not a local class with the same name. -
A name assigned in code that may not run (one arm of
ifor?:, a loop,case,try, callback or the right side of&&,||or??) is not treated as the state value afterwards, unless both arms of anifor?:leave it referring to the same value. -
A name overwritten by destructuring, a loop head or a compound assignment such as
||=is not treated as the state value afterwards. -
A
letorvaralias that any other function assigns is never treated as the state value, whether or not that function runs. -
A mutation in one
casereaches the next only when the first can fall through to it. -
Adjacent
ifstatements on the same unchanging identifier or its!are read as agreeing on its value, and a guard on the switched value that cannot be decided keeps a change from running on to the nextcase. -
A mutation inside a callback counts toward a later setter call for built-in synchronous callback methods such as
forEach,map,Array.fromandString.replace(including methods with no declaration, as on untyped values) and React’sstartTransition,flushSyncandunstable_batchedUpdates. It also counts when the code waits for the work:await load().then(...)(orcatch,finally),await Promise.all(ids.map(async ...))(orallSettled) andawait (async () => {})(). Aconstlist of promises counts when the very next statement isawait Promise.all(tasks), and so does a promise that an inline callback returns to an awaited.then. Other callbacks may run later, including unawaitedasyncones, generators, library helpers and same-named methods declared by your own code or a library. A callback that both mutates and calls the setter is still reported. A callback of an array method called on a literal[], as in[].forEach(...), never runs and is skipped; any other list is assumed to have an element. Only inline callbacks are traced toward a later setter call: a mutation made only inside a separately declared one, as inconst push = (value) => items.push(value); items.forEach(push); setItems(items), is missed. -
Only an argument the method calls counts: the first for most methods, the second for
Array.from,replaceandreplaceAll, and either of the first two forthen. AthisArgis only passed along. -
What awaited
.thenorasyncwork changes reaches the caller after the wait, not a sibling in the sameawait. The exception is what an awaitedasyncmapping or invocation does before its firstawait: its concise body, or its leading expression, variable andreturnstatements. Anif, loop,tryor block ends that prefix. The rule assumes the mapped list is not empty. What it concludes fromPromise.allorallSettledassumes standard promise machinery, including an unmodifiedconstructorlookup: a listed promise whoseconstructorgetter throws, on itself or through a redefinedPromise.prototype, makes evenallSettledreject before the other listed work has finished, and this is not detected. -
A rejection handler (
catch, or the second argument ofthen) does not see what the step before it changed, and acatchsees only what has changed by a point in itstrythat can throw: a call,new,await,yield,throwor loop. - A setter call in a callback that may run later is skipped when the state variable may be reassigned before then: after the callback is passed on, from another function, or in a loop around it.
-
A
letorvarsetter that is reassigned is skipped unless every reassignment is||=or??=(which keep a function) or a later statement in a block that is running the setter call.
How to review or fix
Set a copy instead.Configuration
Set the rule to"off" in loadwise.config.json to drop its findings: