'use client'; import { ComponentProps, ReactNode, useState } from 'react'; import Link from 'next/link'; import LinkWithStatusChild from './primitives/LinkWithStatusChild'; import clsx from 'clsx/lite'; export default function LinkWithStatus({ children, className, loadingClassName, isLoading: isLoadingProp = false, setIsLoading: setIsLoadingProp, ...props }: Omit, 'children'> & { children: ReactNode | ((props: { isLoading: boolean }) => ReactNode) loadingClassName?: string // For hoisting state to a parent component, e.g., isLoading?: boolean setIsLoading?: (isLoading: boolean) => void }) { const [_isLoading, _setIsLoading] = useState(false); const isLoading = isLoadingProp || _isLoading; const setIsLoading = setIsLoadingProp || _setIsLoading; const isControlled = typeof children === 'function'; return {typeof children === 'function' ? children({ isLoading }) : children} ; }