BlueWallet/hooks/useAnimateOnChange.ts

14 lines
452 B
TypeScript
Raw Permalink Normal View History

2024-09-27 14:08:42 +02:00
import { useEffect, useRef } from 'react';
import { LayoutAnimation } from 'react-native';
const useAnimateOnChange = <T>(value: T) => {
const prevValue = useRef<T | undefined>(undefined);
useEffect(() => {
if (prevValue.current !== undefined && prevValue.current !== value) {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
}
prevValue.current = value;
}, [value]);
};
export default useAnimateOnChange;