(outer: React.Ref<T> | undefined, local: React.RefObject<T | null>)
| 9 | */ |
| 10 | export const composedRefCallback = |
| 11 | <T>(outer: React.Ref<T> | undefined, local: React.RefObject<T | null>): React.RefCallback<T> => |
| 12 | (node) => { |
| 13 | local.current = node; |
| 14 | if (typeof outer === "function") { |
| 15 | const cleanup = outer(node); |
| 16 | if (typeof cleanup === "function") { |
| 17 | return () => { |
| 18 | local.current = null; |
| 19 | cleanup(); |
| 20 | }; |
| 21 | } |
| 22 | return undefined; |
| 23 | } |
| 24 | if (outer) outer.current = node; |
| 25 | return undefined; |
| 26 | }; |
| 27 | |
| 28 | /** `composedRefCallback`, kept stable across renders for stable inputs so the |
| 29 | * incoming ref is not detached and reattached on every render. */ |
no test coverage detected