Skip to main content
Home

Built and signed on GitHub Actions

Utility functions and hooks for a variety of React-style frameworks.

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.4.0)
function createUseInitRef
createUseInitRef(useRef: useRefType<unknown>): <T>(init: () => T) => { current: T; }

Creates a hook that will return a ref object like useRef, but is initialized with a value from a callback function. Useful for when you need to initialize a ref with a value that would be expensive to compute on every render.

Examples

Example 1

const useInitRef = createUseInitRef(useRef);

function MyComponent() {
    const ref = useInitRef(() => expensiveComputation());
    return <div>{ref.current.toString()}</div>;
}

Parameters

useRef: useRefType<unknown>

Return Type

<T>(init: () => T) => { current: T; }

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@lixquid/util-react

Import symbol

import { createUseInitRef } from "@lixquid/util-react";
or

Import directly with a jsr specifier

import { createUseInitRef } from "jsr:@lixquid/util-react";

Add Package

pnpm i jsr:@lixquid/util-react
or (using pnpm 10.8 or older)
pnpm dlx jsr add @lixquid/util-react

Import symbol

import { createUseInitRef } from "@lixquid/util-react";

Add Package

yarn add jsr:@lixquid/util-react
or (using Yarn 4.8 or older)
yarn dlx jsr add @lixquid/util-react

Import symbol

import { createUseInitRef } from "@lixquid/util-react";

Add Package

vlt install jsr:@lixquid/util-react

Import symbol

import { createUseInitRef } from "@lixquid/util-react";

Add Package

npx jsr add @lixquid/util-react

Import symbol

import { createUseInitRef } from "@lixquid/util-react";

Add Package

bunx jsr add @lixquid/util-react

Import symbol

import { createUseInitRef } from "@lixquid/util-react";