{"version":3,"file":"setRef.cjs","names":[],"sources":["../../src/setRef/setRef.ts"],"sourcesContent":["import type { MutableRefObject, Ref } from 'react';\n\nfunction isRefObject<T>(ref: unknown): ref is MutableRefObject<T | null> {\n  return !!ref && typeof ref === 'object' && Object.hasOwn(ref, 'current');\n}\n\n/**\n * Assigns a value to an object ref or callback ref.\n *\n * This is useful in components that need to keep an internal ref while also\n * forwarding the same node to a consumer-provided ref.\n *\n * @typeParam T - Ref value type.\n * @param ref - React ref to update. `null` and unsupported values are ignored.\n * @param value - Value assigned to the ref. Pass `null` when clearing it.\n *\n * @example\n * ```tsx\n * const localRef = useRef<HTMLDivElement | null>(null);\n *\n * const assignRef = useCallback((node: HTMLDivElement | null) => {\n *   localRef.current = node;\n *   setRef(forwardedRef, node);\n * }, [forwardedRef]);\n * ```\n */\nexport function setRef<T>(ref: Ref<T> | MutableRefObject<T | null> | null | undefined, value: T | null): void {\n  if (typeof ref === 'function') {\n    ref(value);\n  } else if (isRefObject<T>(ref)) {\n    ref.current = value;\n  }\n}\n"],"mappings":";;AAEA,SAAS,YAAe,KAAiD;CACvE,OAAO,CAAC,CAAC,OAAO,OAAO,QAAQ,YAAY,OAAO,OAAO,KAAK,SAAS;AACzE;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,OAAU,KAA6D,OAAuB;CAC5G,IAAI,OAAO,QAAQ,YACjB,IAAI,KAAK;MACJ,IAAI,YAAe,GAAG,GAC3B,IAAI,UAAU;AAElB"}