Skip to content

Instantly share code, notes, and snippets.

@ericvicenti
Created January 29, 2019 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericvicenti/fb59dac4f7d7e57254e0eab1bf043950 to your computer and use it in GitHub Desktop.
Save ericvicenti/fb59dac4f7d7e57254e0eab1bf043950 to your computer and use it in GitHub Desktop.
import Animated from 'react-native-reanimated';
const defaultApplyValue = (v, dest) => v.setValue(dest);
export default function useAnimatedValue(currentValue, applyValue = defaultApplyValue) {
const [val] = useState(new Animated.Value(currentValue));
useEffect(
() => {
applyValue(val, currentValue);
},
[currentValue],
);
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment