const ExpandableView = ({ expanded = false, children }) => { const [height] =…
- User
const ExpandableView = ({ expanded = false, children }) => { const [height] = useState(new Animated.Value(0)); useEffect(() => { Animated.timing(height, { toValue: expanded ? 100 : 0, duration: 700, easing: Easing.out(Easing.exp), useNativeDriver: false }).start(); }, [expanded, height]); return ( <Animated.View style={{ maxHeight: height, opacity: 1 }}> {height} {children} </Animated.View> ); };
Type 'Value' is not assignable to type 'ReactNode'.ts(2322)
- Assistant
The error you're encountering is due to the fact that you're trying to display the
heightvalue, which is an instance ofAnimated.Value, inside aTextcomponent. TheTextcomponent in React Native expects astringornumberas its child, butAnimated.Valueis not directly a string or number.To display the animated value for debugging purposes inside a
Textcomponent, you need to use an component and interpolate the value to a format that can be rendered as a string.