use-constant
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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);
  // ...

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    32,912
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    32,912
  • 1.1.0
    43,572
  • 1.0.0
    10,746

Package Sidebar

Install

npm i use-constant

Weekly Downloads

24,170

Version

1.1.1

License

MIT

Unpacked Size

2.63 kB

Total Files

7

Last publish

Collaborators

  • andarist