naopoyo.com
  • Docs
  • Tags
  • Bookmarks
  • Tools
  • About
  • Docs
  • Tags
  • Bookmarks
  • Tools
  • About

目次

© naopoyo

🍡

開発日記-2024-01-26 / Next.jsのpathnameの取得

公開日
2年近く前
2024-01-26
更新履歴
GitHubで見る
  • React
  • VS Code
  • 開発日記

Next.jsのサーバーコンポーネントで pathname の取得が簡単にできるようになってた

GitHub - alexdln/nimpl-getters: Implementation of server getters in React Server Components without switching to SSR
Implementation of server getters in React Server Components without switching to SSR - alexdln/nimpl-getters
github.com favicon
github.com
GitHub - alexdln/nimpl-getters: Implementation of server getters in React Server Components without switching to SSR

npmのパッケージをインストールするだけでできる。

Terminal
pnpm add next-impl-getters
server
import { getPathname } from 'next-impl-getters/get-pathname'

export default function Component() {
    const pathname = getPathname()

    return (
        // ...
    )
}

以下のクライアントコンポーネントと同じ感じで取得できる。

client
'use client'

import { usePathname } from 'next/navigation'

export default function Component() {
    const pathname = usePathname()

    return (
        // ...
    )
}

VS Codeの便利な設定 Sticky Scroll の設定方法

スクロールしたときにメソッド名などが上部に固定されて便利。

settings.json
{
  "editor.stickyScroll.enabled": true,
  "editor.stickyScroll.maxLineCount": 5,
}

Reactでタグ名を指定できるコンポーネントの作り方

以下のコードで出力される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>
}

レトロゲーム風のフォント

ゲームを作るときに、このフォントを使ってみよう。

PixelMplus(ピクセル・エムプラス) ‥ 8bitビットマップふうフリーフォント - itouhiroはてなブログ
PixelMplus(ピクセル・エムプラス)というフォントを作成しました。 8bitゲーム機のビットマップフォントのような感じを出せるフリーフォントです。
itouhiro.hatenablog.com favicon
itouhiro.hatenablog.com
PixelMplus(ピクセル・エムプラス) ‥ 8bitビットマップふうフリーフォント - itouhiroはてなブログ

目次

最近更新された記事

🎮
ゲーム開発日記4
14日前 - 2025年11月03日
  • Unity
  • ゲーム開発
🐩
開発日記-2025-11-02 / git worktree について調べる
15日前 - 2025年11月02日
  • 開発日記
🌇
開発日記-2025-10-31 / Xのブックマークに入れてたサイトを読む
18日前 - 2025年10月31日
  • 開発日記