# scroll-position-no-state

scroll-position-no-state is a Claude Code rule that forbids keeping scroll position in useState. It applies to React Native scroll handlers.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 88 repo stars
- Author: alexj11324
- License: AGPL-3.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/alexj11324/Mikka/tree/HEAD/.claude/skills/react-native-skills/rules/scroll-position-no-state.md
- Updated: 2026-11-17
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/scroll-position-no-state

## What it does

The rule directs agents away from updating scroll position through `useState`: scroll events arrive frequently, and repeated state changes trigger renders that can drop frames. For animation, it points to `useSharedValue` and `useAnimatedScrollHandler` from `react-native-reanimated`; for tracking that should not drive rendering, it uses `useRef`.

Writing to a ref or shared value avoids a React render for each scroll event. To add the rule to Claude Code, place `.claude/rules/scroll-position-no-state.md` in the project.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/rules/scroll-position-no-state.md` — The paths frontmatter field limits the files

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### Cursor

**Manually: put the files in place**
- File: `.cursor/rules/scroll-position-no-state.mdc` — Frontmatter: description, globs, alwaysApply

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/scroll-position-no-state.instructions.md` — The applyTo field sets which files it applies to

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/scroll-position-no-state.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/scroll-position-no-state.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/alexj11324/Mikka/tree/HEAD/.claude/skills/react-native-skills/rules/scroll-position-no-state.md

## When to use it
- stop repeated renders during scrolling
- track scroll position for an animation
- read scroll position without changing React state

## Example prompts
- Rewrite the `Feed` scroll handler so each event does not update `useState`.
- Add a scroll-driven animation using the approach from this rule.
- Review the `ScrollView` component and replace state-based scroll tracking with `useRef`.

## Similar
- [compose-state-and-effects](https://affpapa.org/en/nevibecode/skills/compose-state-and-effects.md) — skill · 1500 installs
- [position-sizer](https://affpapa.org/en/nevibecode/skills/position-sizer.md) — skill · 4400 installs
- [revenuecat-store-state](https://affpapa.org/en/nevibecode/skills/revenuecat-store-state.md) — skill · 795 installs
- [phone_scroll](https://affpapa.org/en/nevibecode/prompts/phone-scroll.md) — prompt · ★ 9488 repo stars
- [futures-position-sizer](https://affpapa.org/en/nevibecode/skills/futures-position-sizer.md) — skill · 2900 installs
- [serial-position-effect](https://affpapa.org/en/nevibecode/skills/serial-position-effect.md) — skill · 1400 installs

From the same set: [alexj11324/mikka](https://affpapa.org/en/nevibecode/by/alexj11324/mikka.md) — 47 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
