JSPM

@utilityjs/use-get-latest

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 399
  • Score
    100M100P100Q91666F
  • License MIT

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

Package Exports

  • @utilityjs/use-get-latest
  • @utilityjs/use-get-latest/esm/index.js
  • @utilityjs/use-get-latest/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@utilityjs/use-get-latest) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.