react-doctor/rn-no-dimensions-get
Use `const { width, height } = useWindowDimensions()` — it updates reactively on rotation and resize
- Category: React Native
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: react-native
- Enabled when: framework=react-native and capabilities=react-native
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Verify the call is Dimensions.get(...) or Dimensions.addEventListener(...); the latter was removed in RN 0.72. False positive: a one-shot module-level read for a static StyleSheet constant is fine, but anything consumed by a component should switch to useWindowDimensions so it reacts to rotation, split-screen, and resize.
Fix prompt
Use this once validation confirms the diagnostic is real.
Inside components/hooks use const { width, height } = useWindowDimensions() — it subscribes to rotation, split-screen, and resize automatically. Delete any Dimensions.addEventListener setup/cleanup; the hook handles teardown for you. See https://reactnative.dev/docs/usewindowdimensions
Related rules
More React Native rules from the rules reference:
react-doctor/rn-no-falsy-and-render: Guard numeric-looking conditions: {count > 0 && <X/>}, {Boolean(count) && <X/>}, or {count ? <X/> : null}react-doctor/rn-no-image-children: Replace <Image> with <ImageBackground> to render content over the image: <ImageBackground source={src}>...children...</ImageBackground>react-doctor/rn-no-inline-flatlist-renderitem: Extract renderItem to a named function or wrap in useCallback to avoid re-creating on every renderreact-doctor/rn-no-inline-object-in-list-item: Hoist style/object props outside renderItem (StyleSheet.create, useMemo at list scope, or pass primitives) so memo() row components stop bailingreact-doctor/rn-no-legacy-expo-packages: Migrate to the recommended replacement package — legacy Expo packages are no longer maintained