react-doctor/rn-animation-reaction-as-derived
Replace useAnimatedReaction with `useDerivedValue(() => ..., [deps])` — shorter, native dependency tracking, no side-effect implication
- 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 second argument to useAnimatedReaction is a function whose body is exactly one statement assigning to some sharedValue.value. Multiple statements, a runOnJS call, conditionals, or any logging mean the side-effect semantics are intentional and useDerivedValue would change behavior — that's a false positive.
Fix prompt
Use this once validation confirms the diagnostic is real.
Rewrite as const derived = useDerivedValue(() => prepareExpression). Reanimated tracks shared-value dependencies inside the worklet automatically, so you drop the prepare/reaction split and get the same write to derived.value on each change. See https://docs.swmansion.com/react-native-reanimated/docs/core/useDerivedValue
Related rules
More React Native rules from the rules reference:
react-doctor/rn-bottom-sheet-prefer-native: Use `<Modal presentationStyle="formSheet">` (RN v7+) for native gesture handling and snap pointsreact-doctor/rn-detox-missing-await: Prepend await to the Detox action, waitFor chain, or expect(element(...)) assertion: await element(by.id('submit')).tap()react-doctor/rn-list-callback-per-row: Hoist the handler with useCallback at list scope and pass the row id as a primitive prop, so the row's memo() shallow-compare actually hitsreact-doctor/rn-list-data-mapped: Wrap the projection in `useMemo(() => items.map(...), [items])` so the list's `data` prop has a stable reference across parent rendersreact-doctor/rn-list-missing-estimated-item-size: Add estimatedItemSize so FlashList/LegendList sizes its initial container pool correctly: <FlashList data={items} estimatedItemSize={64} />