Skip to content

Andarist/use-constant

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •