BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/diceui/radix/compose-refs

compose-refs

diceui-radix/compose-refs
FreeUtility

diceui/radix publishes no description for this item.

Install it

npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/compose-refs.json

Source

lib/compose-refs.tsraw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/compose-refs.json
1/**
2 * @see https://github.com/radix-ui/primitives/blob/main/packages/react/compose-refs/src/compose-refs.tsx
3 */
4
5import * as React from "react";
6
7type PossibleRef<T> = React.Ref<T> | undefined;
8
9/**
10 * Set a given ref to a given value
11 * This utility takes care of different types of refs: callback refs and RefObject(s)
12 */
13function setRef<T>(ref: PossibleRef<T>, value: T) {
14 if (typeof ref === "function") {
15 return ref(value);
16 }
17
18 if (ref !== null && ref !== undefined) {
19 ref.current = value;
20 }
21}
22
23/**
24 * A utility to compose multiple refs together
25 * Accepts callback refs and RefObject(s)
26 */
27function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {
28 return (node) => {
29 let hasCleanup = false;
30 const cleanups = refs.map((ref) => {
31 const cleanup = setRef(ref, node);
32 if (!hasCleanup && typeof cleanup === "function") {
33 hasCleanup = true;
34 }
35 return cleanup;
36 });
37
38 // React <19 will log an error to the console if a callback ref returns a
39 // value. We don't use ref cleanups internally so this will only happen if a
40 // user's ref callback returns a value, which we only expect if they are
41 // using the cleanup functionality added in React 19.
42 if (hasCleanup) {
43 return () => {
44 for (let i = 0; i < cleanups.length; i++) {
45 const cleanup = cleanups[i];
46 if (typeof cleanup === "function") {
47 cleanup();
48 } else {
49 setRef(refs[i], null);
50 }
51 }
52 };
53 }
54 };
55}
56
57/**
58 * A custom hook that composes multiple refs
59 * Accepts callback refs and RefObject(s)
60 */
61function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {
62 // biome-ignore lint/correctness/useExhaustiveDependencies: we want to memoize by all values
63 return React.useCallback(composeRefs(...refs), refs);
64}
65
66export { composeRefs, useComposedRefs };

Files it writes

  • lib/compose-refs.ts

Facts

Registry
diceui/radix
Type
registry:lib
Access
Free
Files written
1
Licence
the repository states none
In the index
at or before 2026-08-08
Last confirmed
3 days ago

Go to the source

www.diceui.com sadmann7/diceui on GitHub Raw registry item This item as JSON

More from diceui/radix

All 58 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
utilsutilsdiceui/radixUtilitiesFree2 deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex