import { RefObject, useRef } from 'react'
export type UseNodeProps = {
ref?: RefObject
map: (node: A) => HTMLElement | null
}
const idFn = _ => _
export function useNode(props: UseNodeProps = { map: idFn }) {
const internalRef = useRef(null)
const ref = props.ref || internalRef
const mapRef = useRef(null)
if (ref.current) {
mapRef.current = props.map(ref.current)
}
return {
current: mapRef.current,
ref,
}
}