{"record":{"id":"152e95d857b79030","repo":"oxc-project/oxc","slug":"the-ref-s-value-current-is-accessed-directly-in","errorCode":null,"errorMessage":"The ref's value `.current` is accessed directly in the effect cleanup function.","messagePattern":"The ref's value `\\.current` is accessed directly in the effect cleanup function\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/exhaustive_deps.rs","lineNumber":208,"sourceCode":"    OxcDiagnostic::warn(format!(\n        \"React Hook {hook_name} has an unnecessary dependency: {dep_name}.\"\n    ))\n    .with_label(span)\n    .with_help(\"Consider removing it from the dependency array. Outer scope values aren't valid dependencies because mutating them doesn't re-render the component.\")\n    .with_error_code_scope(SCOPE)\n}\n\nfn infinite_rerender_call_to_set_state_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"React Hook {hook_name} contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.\"\n    ))\n    .with_label(span)\n    .with_help(\"Consider adding an empty list of dependencies to make it clear which values are intended to be stable.\")\n    .with_error_code_scope(SCOPE)\n}\n\nfn ref_accessed_directly_in_effect_cleanup_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"The ref's value `.current` is accessed directly in the effect cleanup function.\")\n        .with_label(span)\n        .with_help(\"The ref value will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by react, copy it to a variable inside the effect and use that variable in the cleanup function.\")\n        .with_error_code_scope(SCOPE)\n}\n\nfn functions_returned_from_use_effect_event_must_not_be_included_in_dependency_array(\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Functions returned from `useEffectEvent` must not be included in the dependency array.\",\n    )\n    .with_label(span)\n    .with_help(\"Remove the dependency from the dependency array.\")\n    .with_error_code_scope(SCOPE)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct ExhaustiveDeps(Box<ExhaustiveDepsConfig>);","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs#L190-L226","documentation":"Raised by react/exhaustive_deps when the effect's cleanup function reads `ref.current` directly. At the throw site the cleanup captures the mutable ref object and dereferences `.current` at cleanup time; by then React has usually already set `.current` to null (for ref objects attached to DOM nodes), so the code reads a stale or null value instead of the value from when the effect ran. run() scans cleanup bodies for `.current` member accesses and reports them.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:208 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Capture ref.current in a local variable inside the effect body and use that captured value in the cleanup.","Ensure the ref is only cleared after cleanup completes."],"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"}