React275 Documents

Window Global

Do not access the window global in React code. Use framework hooks, contexts, injected dependencies, or focused adapters so components remain testable and independent of browser-global state.

Correct

const location = useLocation()
const [searchParams] = useSearchParams()

Incorrect

const searchParams = new URLSearchParams(window.location.search)

Fix

Replace window access with the applicable React or router abstraction. Isolate an unavoidable browser API behind a focused adapter and inject it where it is consumed.