@utilityjs/use-get-latest
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

useGetLatest

A React hook that stores & updates ref.current with the most recent value.

license npm latest package npm downloads types

npm i @utilityjs/use-get-latest | yarn add @utilityjs/use-get-latest

Usage

import useGetLatest from "@utilityjs/use-get-latest";
import * as React from "react";

const useAttachDomClick = (callback) => {
  const cachedCallback = useGetLatest(callback);

  React.useEffect(() => {
    document.addEventListener("click", cachedCallback.current);
    return () => {
      document.removeEventListener("click", cachedCallback.current);
    }
  }, [])
};

API

useGetLatest(value)

declare const useGetLatest: <T>(value: T) => MutableRefObject<T>;

value

The value to be stored.

Package Sidebar

Install

npm i @utilityjs/use-get-latest

Weekly Downloads

79

Version

1.0.2

License

MIT

Unpacked Size

4.23 kB

Total Files

8

Last publish

Collaborators

  • mimshins