"hooks/useStableCallback" | @uirouter/react
Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "hooks/useStableCallback"

Index

Functions

Functions

useStableCallback

  • useStableCallback<T>(unstableCallback: T): T
  • Returns a stabilized callback reference which delegates to the most recent unstable callback

    This is similar to useCallback, but allows unstableCallback to access the most recent values from the closure. This can be useful if the callback is being stored long term, such as in the Transition Hook registry.

    Example:

    const latestValueFromProps = props.value
    const transitionHook = useStableCallback(() => console.log(latestValueFromProps));
    useEffect(() => {
      const deregister = transitionService.onBefore({ exiting: 'someState' }, transitionHook);
      return () => deregister();
    }, []);

    Type parameters

    • T: Function

    Parameters

    • unstableCallback: T

    Returns T

Generated using TypeDoc