JSPM

use-constant

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 33199
  • Score
    100M100P100Q135583F
  • License MIT

React hook for creating a value exactly once.

Package Exports

  • use-constant

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 (use-constant) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

use-constant

React hook for creating a value exactly once. useMemo doesn't give this guarantee unfortunately - https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily

Usage

Install the package

npm install use-constant
# OR
yarn add use-constant

In your code

import useConstant from 'use-constant';

const MyComponent = () => {
  // Give useConstant() a function which should be be executed exactly once and
  // return in it your constant value
  const myConstantValue = useConstant(() => 42);
  // ...