fix(SW-3691): Setup one prettier config for whole repo * Setup prettierrc in root and remove other configs Approved-by: Joakim Jäderberg Approved-by: Linus Flood
25 lines
555 B
TypeScript
25 lines
555 B
TypeScript
import type { Ref, RefCallback } from "react"
|
|
|
|
/**
|
|
* Merges multiple refs into a single ref callback.
|
|
* Useful when you need to forward a ref while also using react-hook-form's field.ref.
|
|
*
|
|
* @example
|
|
* ```tsx
|
|
* <Input ref={mergeRefs(field.ref, forwardedRef)} />
|
|
* ```
|
|
*/
|
|
export function mergeRefs<T>(
|
|
...refs: Array<Ref<T> | undefined>
|
|
): RefCallback<T> {
|
|
return (node: T | null) => {
|
|
refs.forEach((ref) => {
|
|
if (typeof ref === "function") {
|
|
ref(node)
|
|
} else if (ref) {
|
|
ref.current = node
|
|
}
|
|
})
|
|
}
|
|
}
|