Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/react-compiler-reanimated-shared-values.md
1---2title: Use .get() and .set() for Reanimated Shared Values (not .value)3impact: LOW4impactDescription: required for React Compiler compatibility5tags: reanimated, react-compiler, shared-values6---78## Use .get() and .set() for Shared Values with React Compiler910With React Compiler enabled, use `.get()` and `.set()` instead of reading or11writing `.value` directly on Reanimated shared values. The compiler can't track12property access—explicit methods ensure correct behavior.1314**Incorrect (breaks with React Compiler):**1516```tsx17import { useSharedValue } from 'react-native-reanimated'1819function Counter() {20const count = useSharedValue(0)2122const increment = () => {23count.value = count.value + 1 // opts out of react compiler24}2526return <Button onPress={increment} title={`Count: ${count.value}`} />27}28```2930**Correct (React Compiler compatible):**3132```tsx33import { useSharedValue } from 'react-native-reanimated'3435function Counter() {36const count = useSharedValue(0)3738const increment = () => {39count.set(count.get() + 1)40}4142return <Button onPress={increment} title={`Count: ${count.get()}`} />43}44```4546See the47[Reanimated docs](https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue/#react-compiler-support)48for more.49