New
Introducing React Bench, see how different models perform on React code

react-doctor/rn-no-set-native-props

Drive the prop via state, an Animated.Value (useNativeDriver: true), or a Reanimated shared value instead of imperative setNativeProps

  • Category: Bugs
  • Severity: warn
  • Source: oxlint-plugin-react-doctor
  • Framework: react-native
  • Enabled when: framework=react-native and capabilities=react-native
  • Tags: react-native
  • Default: Enabled

Validate the diagnostic

Confirm the reported code matches this rule before you edit it.

Fires on a CallExpression whose callee is a static non-computed .setNativeProps member access AND whose receiver is itself a static non-computed .current member access — i.e. the *.current.setNativeProps(...) or optional-chained *.current?.setNativeProps(...) React host-ref shape (e.g. inputRef.current.setNativeProps({ text }), this.rootViewRef.current.setNativeProps(...), or a chained inputRef.current?.textInputRef.current?.setNativeProps(...)). The rule deliberately only matches the ref .current escape hatch. False positives a reviewer should SUPPRESS: an uncalled member access used as a value (const fn = ref.current.setNativeProps), setNativeProps on a non-.current receiver such as a plain config/options object (config.setNativeProps({...})), a callback-ref form with no .current (iconRef.setNativeProps(...), explicitly out of v1 scope), and other imperative ref methods (inputRef.current.focus()).

How to fix

Follow the rule guidance while preserving unrelated behavior.

Copyable fix prompt

Copy this self-contained prompt into your coding agent after you confirm the diagnostic.

Replace the imperative call with declarative state: hold the value in useState and pass it as a prop (e.g. instead of inputRef.current.setNativeProps({ text }), keep const [text, setText] = useState(...) and render <TextInput value={text} />). For animated visual props, drive them through an Animated.Value with useNativeDriver: true, or a Reanimated useSharedValue/useAnimatedStyle, so updates run on the native thread. setNativeProps is a warn-and-return no-op under the New Architecture (Fabric, default since RN 0.76), so the imperative update silently stops changing the view after migration.

More Bugs rules from the rules reference: