Org Skills

React and React Native anti-patterns — the one shared list

Supporting material for react-development. Agents load it on demand; it ships inside the skill folder.

RawSource

Verified 2026-09 against react.dev, docs.expo.dev and docs.swmansion.com. This is the only copy; react-* and react-native-* skills and both instruction files link here instead of repeating it. Each entry: pattern → fix (why).

State and effects

  • Copying props or derived values into state and syncing them with useEffect → derive during render; reset with a key when a prop identity changes. Two sources of truth drift for one render and cause the most common React bug. https://react.dev/learn/you-might-not-need-an-effect
  • Fetching in useEffect with hand-rolled loading/error flags → a query hook (TanStack Query v5), a route loader (React Router) or an async Server Component (Next.js). You get caching, dedup, cancellation via signal and no stale-response races.
  • Responding to a user event inside an effect (useEffect(() => { if (submitted) … }, [submitted])) → do the work in the event handler.
  • Silencing react-hooks/exhaustive-deps → restructure: split the effect, move the value inside, or use useEffectEvent (React 19.2+) for the non-reactive part. Suppressed deps mean stale closures.
  • Mutating state (items.push(x); setItems(items)) or mutating props/refs during render → return new objects; keep components pure. The React Compiler and StrictMode depend on purity; impure code is silently not optimised. https://react.dev/reference/rules
  • useEffectEvent used to hide a dependency you actually want to react to → only wrap the part that reads latest values without re-running; the effect still lists what triggers it.
  • use(promise) created inside render → the promise must come from a cache, a Server Component or a stable source; a new promise each render suspends forever.

Rendering, keys and composition

  • Index or Math.random() keys on reorderable, filterable or editable lists → stable ids from the data. Wrong keys leak state between rows and remount everything.
  • Context for fast-changing values (mouse position, form values, a whole store object) → a store with selectors (Zustand, Jotai) or split contexts by change frequency. Every consumer re-renders on any change.
  • Prop-drilling a setter four levels down → colocate state, pass children, or use a store.
  • forwardRef, defaultProps, class components in new React 19 code → ref is a plain prop; default values in the destructuring; function components. react-error-boundary covers the one remaining class use case.
  • Business logic (pricing, permissions, formatting rules) inside JSX or route files → a model/ module with plain functions you can unit test.
  • useMemo/useCallback/memo everywhere by policy → none by hand when the React Compiler is on; otherwise only for the prop a Profiler shows is breaking a memoised child. https://react.dev/learn/react-compiler
  • dangerouslySetInnerHTML with unsanitised content → sanitise (DOMPurify) or render structured data. XSS.
  • Returning null for the error or empty state → render designed loading, empty, error (with retry) and success states.

Data and forms

  • Server data in Redux/Zustand → query cache (TanStack Query) or server rendering; client stores hold only client state.
  • One field = one useState + e.target.value handlers for a real form → React Hook Form + Zod (zodResolver), or a Server Action with useActionState in Next.js.
  • Validation that lives only on the client → the same Zod schema runs in the Server Action, loader action or API handler.
  • Reading window, localStorage or document in a component that can render on the server → mark it 'use client' and read inside an effect, or use useSyncExternalStore with a server snapshot.

Performance and measurement

  • Optimising without a baseline → record the metric (INP, LCP, JS FPS, TTI) on the target device first; judge every change against it.
  • React.memo on a component that receives a fresh object/array/function prop every render → stabilise the prop or drop the memo; it never hits.
  • Full-library imports (import _ from 'lodash', whole icon packs, moment) → per-function imports, date-fns/Intl, tree-shakeable icons.
  • Disabling StrictMode to "fix" double renders in dev → fix the impure effect it exposed.

React Native specific

  • ScrollView + .map() for data lists, or nested same-direction scroll views → FlashList v2 (no estimatedItemSize) with ListHeaderComponent/ListFooterComponent. https://shopify.github.io/flash-list/docs/v2-changes
  • Animated.Value driven by setState per frame, PanResponder, or runOnJS → Reanimated 4 shared values, Gesture Handler Gesture.Pan(), and scheduleOnRN from react-native-worklets only on gesture end. https://docs.swmansion.com/react-native-reanimated/docs/guides/migration-from-3.x/
  • Layout layout animation → LinearTransition (the 2.x name is gone). https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/layout-transitions/
  • Conditionally rendering different <Stack> trees for auth, or <Redirect> in the root layout on SDK 53+ → <Stack.Protected guard={…}>; keep every screen deep-linkable. https://docs.expo.dev/router/advanced/authentication/
  • Strings outside <Text>, <div>/className/window in native code → Text, View, StyleSheet; web APIs do not exist on device.
  • TouchableOpacity, <View onTouchEnd> as buttons → Pressable with accessibilityRole="button", label and state.
  • Tokens in AsyncStorage, MMKV or a persisted store → expo-secure-store. MMKV encryption still needs a key that itself must live in SecureStore, so put the token there directly.
  • Dimensions.get('window') at module scope → useWindowDimensions(); module-scope values ignore rotation and foldables.
  • Core SafeAreaView, or SafeAreaView nested inside navigators → useSafeAreaInsets() from react-native-safe-area-context applied as padding (core SafeAreaView is deprecated since SDK 54).
  • Editing ios/ or android/ in a managed Expo app → config plugins in app.json/app.config.ts; the folders are regenerated by prebuild.
  • Trying to disable the New Architecture "for now" → impossible since RN 0.82 / SDK 55 (newArchEnabled=false is ignored); replace or wrap the blocking dependency. https://reactnative.dev/blog/2025/10/08/react-native-0.82
  • Expecting Expo Router to code-split native bundles → async routes "do not support native production apps yet"; defer module side effects with inline require() instead. https://docs.expo.dev/router/reference/async-routes/