import React, { useRef, useState, useEffect } from 'react'; import { View, Animated } from 'react-native'; import { animateLoop } from './helpers'; import { styles } from './styles'; const Placeholder = ({ animated, style }: any) => { const animating = useRef(false); const [width, setWidth] = useState(0); const animatedValue = useRef(new Animated.Value(0)).current; useEffect(() => { if (width > 0 && animating.current === false && animated === true) { animating.current = true; animateLoop({ variable: animatedValue, toValue: 1, }); } }, [width, animated, animatedValue]); return ( { setWidth(event.nativeEvent.layout.width); }} > {animated === true && ( )} ); }; export default Placeholder;