import { SetStateAction, useCallback, useState } from 'react' export function useStateRef( defaultRef: T, processNode: (node: any) => SetStateAction ): [T, (newNode: any) => void] { const [node, setNode] = useState(defaultRef) const setRef = useCallback( (newNode: HTMLElement) => { setNode(processNode(newNode)) }, [processNode] ) return [node, setRef] }