{"record":{"id":"7005eb0edbcd4b42","repo":"oxc-project/oxc","slug":"do-not-use-setstate-in-componentwillupdate","errorCode":null,"errorMessage":"Do not use `setState` in `componentWillUpdate`.","messagePattern":"Do not use `setState` in `componentWillUpdate`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/no_will_update_set_state.rs","lineNumber":17,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    config::ReactVersion,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    rules::ContextHost,\n    utils::{AllowedOrDisallowInFunc, is_es5_component, is_es6_component},\n};\n\nfn no_will_update_set_state_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use `setState` in `componentWillUpdate`.\")\n        .with_help(\"Updating state during the update step can lead to indeterminate component state and is not allowed.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoWillUpdateSetState(AllowedOrDisallowInFunc);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows using `setState` in the `componentWillUpdate` lifecycle method.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Updating the state during the component update step can lead to indeterminate component state and is not allowed.\n    /// This can cause unexpected behavior and bugs in your React application.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/no_will_update_set_state.rs#L1-L35","documentation":"Raised by react/no_will_update_set_state when a `setState` call occurs inside `componentWillUpdate`. At the throw site updating state during the update phase forces React to re-render in the same pass, which is disallowed and leads to render loops or the notorious 'Cannot update during an existing state transition' warning. run() finds setState calls within the body of componentWillUpdate methods (checked only for class components per React version config) and reports the call site.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/no_will_update_set_state.rs:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the state update to componentDidUpdate or derive state via getDerivedStateFromProps.","Compute the value during render instead of storing it in state."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}