import React__default, { useMemo, isValidElement } from 'react';

/**
 * Returns the first React Child that receives `true` from isCorrectComponent
 * @param children React Children
 * @param isCorrectComponent a function that accepts a ReactElement and returns a boolean.
 * @returns The first child component that returns true on isCorrectComponent
 */
function useChildComponent(children, isCorrectComponent) {
    return useMemo(() => {
        return React__default.Children.toArray(children).find(d => isValidElement(d) && isCorrectComponent(d));
    }, [children]);
}

export { useChildComponent as u };
