mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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.
35 lines
720 B
TypeScript
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)</>
|
|
)}
|
|
</>
|
|
)
|
|
}
|