UNPKG

@chakra-ui/react-utils

Version:

React utilities and helpers for Chakra UI

26 lines (24 loc) 458 B
// src/refs.ts import { isFunction } from "@chakra-ui/utils"; function assignRef(ref, value) { if (ref == null) return; if (isFunction(ref)) { ref(value); return; } try { ref.current = value; } catch (error) { throw new Error(`Cannot assign value '${value}' to ref '${ref}'`); } } function mergeRefs(...refs) { return (node) => { refs.forEach((ref) => assignRef(ref, node)); }; } export { assignRef, mergeRefs };