Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.ui

Avoid setState in componentDidMount

Synchronous state updates during mount trigger an extra render before the browser paints the initial tree.

#Metadata

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

#Why it matters

Initial state belongs in the constructor or class field initializers so the first render already reflects the mounted view.

#Remediation

Move the initial value into state initialization or derive it from props with a guarded update strategy.

#Repository path

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