Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.ui

Guard setState in componentDidUpdate

Unconditional setState in componentDidUpdate can recurse through renders when props or state change on every pass.

#Metadata

Rule ID
ts.react.no-set-state-in-component-did-update
Severity
medium
Confidence
0.8
Languages
javascript, typescript
Presets
recommended, strict
Stability
experimental
Applies to
function
Tags
react, rules-catalog, ui

#Why it matters

Updates should compare against prevProps or prevState so the component only re-renders when inputs actually changed.

#Remediation

Wrap the update in a conditional that compares prevProps or prevState, or move synchronization into getDerivedStateFromProps.

#Repository path

The generated metadata points to critiq-rules/libs/rules/catalog/rules/typescript/ts.react.no-set-state-in-component-did-update.rule.yaml.