@hmans/use-const
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@hmans/use-const

Summary

useConst, a simple hook that allows you to define a contant value that will never change during the lifetime of the component.

import { useConst } from "@hmans/use-const"

const MyComponent = () => {
  const foo = useConst(() => new Foo())
  /* ... */
}

Motivation

Typically, you might use useMemo or useState for these things. useMemo doesn't give you a guarantee that it will never re-run its initializar function (which can be bad, depending on what kind of value you're dealing with), and useState adds state tracking overhead that sometimes is not needed.

Readme

Keywords

none

Package Sidebar

Install

npm i @hmans/use-const

Weekly Downloads

1,178

Version

0.0.1

License

MIT

Unpacked Size

3.79 kB

Total Files

9

Last publish

Collaborators

  • hendrik.mans