useRef.d.ts 707 B

12345678910111213141516
  1. import { MutableRefObject } from 'react';
  2. /**
  3. * creates a MutableRef with ref change callback
  4. * @param initialValue - initial ref value
  5. * @param {Function} callback - a callback to run when value changes
  6. *
  7. * @example
  8. * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
  9. * ref.current = 1;
  10. * // prints 0 -> 1
  11. *
  12. * @see https://reactjs.org/docs/hooks-reference.html#useref
  13. * @see https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
  14. * @returns {MutableRefObject}
  15. */
  16. export declare function useCallbackRef<T>(initialValue: T | null, callback: (newValue: T | null, lastValue: T | null) => void): MutableRefObject<T | null>;