Files
Andrew ClarkandGitHub 3ff99bd0e8 Re-implement hmr-refresh in terms of refresh (#87135)
Based on:
- #87134 

---

hmr-refresh-reducer is identical to refresh-reducer except for the fact
that it doesn't evict the prefetch cache. So this refactors both
implementations to call the same shared function.
2025-12-15 18:27:14 -05:00

35 lines
720 B
TypeScript

'use client'
import Link, { type LinkProps } from 'next/link'
import { useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
}: {
href: string
children?: React.ReactNode
prefetch?: LinkProps['prefetch']
}) {
const [isVisible, setIsVisible] = useState(false)
const resolvedChildren = children ?? href
return (
<>
<input
type="checkbox"
checked={isVisible}
onChange={() => setIsVisible(!isVisible)}
data-link-accordion={href}
/>
{isVisible ? (
<Link href={href} prefetch={prefetch}>
{resolvedChildren}
</Link>
) : (
<>{resolvedChildren} (link is hidden)</>
)}
</>
)
}