home / skills / sovranbitcoin / sovran / animation-with-react-compiler
This skill guides using React Native Reanimated shared values with React Compiler by applying get() and set() for compatibility and safety.
npx playbooks add skill sovranbitcoin/sovran --skill animation-with-react-compilerReview the files below or copy the command above to add this skill to your agents.
---
name: animation-with-react-compiler
description: Provides React Native Reanimated guidelines for using shared values with React Compiler. Applies to tasks involving useSharedValue, shared values, React Compiler compatibility, or accessing/modifying shared value values.
---
# Animation with React Compiler
## Overview
Guidelines for using React Native Reanimated shared values with React Compiler. When using React Compiler, you must use the `get()` and `set()` methods instead of directly accessing the `value` property to ensure compatibility with React Compiler standards.
## When to Apply
Reference these guidelines when:
- Working with React Compiler enabled projects
- Using `useSharedValue` in components
- Accessing or modifying shared value values
- Ensuring React Compiler compatibility with Reanimated
## Key Guideline
### Use get() and set() Methods Instead of .value
When working with the React Compiler, you should refrain from accessing and modifying the `value` property directly. Instead, use the `get()` and `set()` methods. They're the alternative API for `useSharedValue`, compliant with the React Compiler standards.
**Don't do this** – accessing `.value` directly:
```tsx
function App() {
const sv = useSharedValue(100);
const animatedStyle = useAnimatedStyle(() => {
"worklet";
return { width: sv.value * 100 }; // ❌ Direct property access
});
const handlePress = () => {
sv.value = sv.value + 1; // ❌ Direct property modification
};
}
```
**Instead**, use `get()` and `set()` methods:
```tsx
function App() {
const sv = useSharedValue(100);
const animatedStyle = useAnimatedStyle(() => {
"worklet";
return { width: sv.get() * 100 }; // ✅ Using get() method
});
const handlePress = () => {
sv.set((value) => value + 1); // ✅ Using set() method
};
}
```
## Usage Patterns
### Reading Shared Values
```tsx
// ✅ In worklets (useAnimatedStyle, useDerivedValue, etc.)
const animatedStyle = useAnimatedStyle(() => {
return { opacity: sv.get() };
});
// ✅ In useEffect or callbacks
useEffect(() => {
console.log(sv.get());
}, []);
```
### Modifying Shared Values
```tsx
// ✅ Direct value assignment
sv.set(100);
// ✅ Using updater function
sv.set((currentValue) => currentValue + 1);
// ✅ With animation functions
sv.set(withSpring(1.2));
sv.set(withTiming(0.8, { duration: 300 }));
```
## Benefits
- **React Compiler Compatible**: Works seamlessly with React Compiler
- **Consistent API**: Provides a consistent method-based API
- **Type Safety**: Better TypeScript support and type inference
- **Future Proof**: Aligns with React Compiler standards and best practices
This skill provides clear, actionable guidelines for using React Native Reanimated shared values when a project uses the React Compiler. It explains why you should avoid direct .value access and shows the safe get()/set() alternatives for reading and updating shared values. The guidance focuses on compatibility, type safety, and predictable behavior with the React Compiler.
The skill inspects code patterns that read or write useSharedValue instances and recommends replacing direct .value access with sv.get() and sv.set(...). It covers reading inside worklets and effects, updating via direct values, updater functions, and animation wrappers (withSpring/withTiming). It enforces API usage that aligns with React Compiler constraints and TypeScript safety.
Why not use sv.value directly?
Direct .value access is incompatible with React Compiler expectations and can break compiler optimizations and type inference. get()/set() ensure compatibility and predictable behavior.
Can I use get() outside worklets?
Yes. sv.get() works in worklets and in normal JS contexts like useEffect or callbacks. It provides a consistent read API across contexts.