scroll-position-no-state — Claude Code rule: purpose and setup
scroll-position-no-state is a Claude Code rule that forbids keeping scroll position in useState. It applies to React Native scroll handlers.
AGPL-3.0 ★ 88 updated 2026-11-17
.claude/rules/scroll-position-no-state.mdWhat scroll-position-no-state 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.
What it helps with
- stop repeated renders during scrolling
- track scroll position for an animation
- read scroll position without changing React state
Example prompts for the agent
- Rewrite the
Feedscroll handler so each event does not updateuseState. - Add a scroll-driven animation using the approach from this rule.
- Review the
ScrollViewcomponent and replace state-based scroll tracking withuseRef.
How to install scroll-position-no-state
Manually: put the files in place
.claude/rules/scroll-position-no-state.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/scroll-position-no-state.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/scroll-position-no-state.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/scroll-position-no-state.mdManually: put the files in place
.clinerules/scroll-position-no-state.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about scroll-position-no-state
How do I install scroll-position-no-state in Claude Code?
Add .claude/rules/scroll-position-no-state.md to the project.
What does scroll-position-no-state do?
It prohibits storing scroll position in useState. For animations it points to a shared value from react-native-reanimated; for tracking that should not trigger rendering, it uses useRef.
What should replace useState for scroll position?
Use useSharedValue with useAnimatedScrollHandler for animation. Use useRef when the value is only tracked and should not trigger a render.