UNPKG

react-native-wagmi-charts

Version:

A sweet candlestick chart for React Native

14 lines (12 loc) 485 B
import React from 'react'; export function usePrevious<T>(value: T) { // The ref object is a generic container whose current property is mutable ... // ... and can hold any value, similar to an instance property on a class const ref = React.useRef<T>(); // Store current value in ref React.useEffect(() => { ref.current = value; }, [value]); // Only re-run if value changes // Return previous value (happens before update in useEffect above) return ref.current; }