New
Introducing React Doctor for Enterprise

react-hooks-js/globals

Validates against assignment/mutation of globals during render, part of ensuring that [side effects must render outside of render](https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Fires on assignments or mutations to module-scope let/var bindings, frozen const-object properties, or window/globalThis/document.X writes during the synchronous body of a component or hook — e.g. let renderCount; renderCount++ at the top of a component, or window.user = id mid-render. False positive: the mutation lives inside a useEffect, event handler, or async callback rather than executing during render itself.

Fix prompt

Use this once validation confirms the diagnostic is real.

Move mutable per-component state into useState/useReducer (or useRef for non-rendering scratchpads); move DOM and window writes into useEffect (or useLayoutEffect when the write must precede paint, e.g. document.title). For cross-component values, lift to context via createContext + useContext. Globals mutated during render break Fast Refresh, StrictMode double-invocation, and the React Compiler. See https://react.dev/reference/eslint-plugin-react-hooks/lints/globals

More React Compiler rules from the rules reference:

  • react-hooks-js/hooks: Validates the rules of hooks
  • react-hooks-js/immutability: Validates against mutating props, state, and other values that [are immutable](https://react.dev/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable)
  • react-hooks-js/incompatible-library: Validates against usage of libraries which are incompatible with memoization (manual or automatic)
  • react-hooks-js/preserve-manual-memoization: Validates that existing manual memoized is preserved by the compiler. React Compiler will only compile components and hooks if its inference [matches or exceeds the existing manual memoization](https://react.dev/learn/react-compiler/introduction#what-should-i-do-about-usememo-usecallback-and-reactmemo)
  • react-hooks-js/purity: Validates that [components/hooks are pure](https://react.dev/reference/rules/components-and-hooks-must-be-pure) by checking that they do not call known-impure functions