(ref, createHandle, args)
| 312 | * @returns {void} |
| 313 | */ |
| 314 | export function useImperativeHandle(ref, createHandle, args) { |
| 315 | currentHook = 6; |
| 316 | useLayoutEffect( |
| 317 | () => { |
| 318 | if (typeof ref == 'function') { |
| 319 | const result = ref(createHandle()); |
| 320 | return () => { |
| 321 | ref(null); |
| 322 | if (result && typeof result == 'function') result(); |
| 323 | }; |
| 324 | } else if (ref) { |
| 325 | ref.current = createHandle(); |
| 326 | return () => (ref.current = null); |
| 327 | } |
| 328 | }, |
| 329 | args == null ? args : args.concat(ref) |
| 330 | ); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * @template {unknown} T |
searching dependent graphs…