
npmのパッケージをインストールするだけでできる。
pnpm add next-impl-gettersimport { getPathname } from 'next-impl-getters/get-pathname'
export default function Component() {
const pathname = getPathname()
return (
// ...
)
}以下のクライアントコンポーネントと同じ感じで取得できる。
'use client'
import { usePathname } from 'next/navigation'
export default function Component() {
const pathname = usePathname()
return (
// ...
)
}スクロールしたときにメソッド名などが上部に固定されて便利。
{
"editor.stickyScroll.enabled": true,
"editor.stickyScroll.maxLineCount": 5,
}以下のコードで出力されるHTMLは <main>Hello.</main> になる。
import { PropsWithChildren } from 'react'
export interface ComponentProps extends PropsWithChildren {
tagName?: keyof JSX.IntrinsicElements
}
export default function Component({ tagName, children }: ComponentProps) {
const TagName = tagName ?? 'div' // TagName は大文字から始める必要がある
return <TagName>{children}</TagName>
}
function Page() {
return <Component tagName="main">Hello.</Component>
}ゲームを作るときに、このフォントを使ってみよう。
