JSPM

@hmans/use-const

0.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 464
    • Score
      100M100P100Q101354F
    • License MIT

    A simple `useConst` hook for when you don't trust `useMemo`. ;-)

    Package Exports

    • @hmans/use-const
    • @hmans/use-const/dist/hmans-use-const.cjs.js
    • @hmans/use-const/dist/hmans-use-const.esm.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 (@hmans/use-const) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @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.