Next.js のおべんきょう

ここで実装していく

App router 初めて触るからまずドキュメント

head 要素は export const metadata
で入れれる

疑問:body 要素にidとかclassNameのせたいときとかどうするんだろ?

TS71005: "className" is not a valid layout prop.
って言われるんだよなー。idもしかり。

Next.js でfontawesome使うとき

template.tsxは状態変える必要があるときにつかう。ハンバーガーメニューとか。
layout.tsxと同じ階層にあるときはlayoutの子要素になる(layout.tsxのchildrenのなか)

ハンバーガーメニューはちょっと違うな

試しにハンバーガーメニューをlayout.tsxにおいてみるとそんな気はしてたけどエラー。
metadataと共存できないから、やっぱりハンバーガーメニューもtemplate.tsxかな?
./src/app/layout.tsx
ReactServerComponentsError:
You are attempting to export "metadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https://nextjs.org/docs/getting-started/react-essentials#the-use-client-directive

import/order でうまくreactとかnextが一番上にきてくれなかったけど、
pathGroupsExcludedImportTypes: ['builtin']したらできた

トップ以外はレイアウトを共通化したいとかのときはRoute Groupsでlayout.tsxをつくる。
配下で更に入れ子にできるので、「このディレクトリだけボタン足したい」というときは、そのディレクトリ内でlayout.tsx作ればおk

eslint まわりあんましよくわかってないなあって反省してる

CSS Modulesってpostcssに対応してない?
Syntax error: Selector "&:hover" is not pure (pure selectors must contain at least one local class or id)
って怒られるな……

storybookで @/components/**/*
みたいなパスが解決できてない!ページ内でもだめならtsconfig.jsの設定だよね〜ってページに作ったコンポーネント入れたけど、ページ側はエラーなしで表示できた。(ただしpostcssでエラー)

tailwindcss でなんらかの拡張(特にcolorとか)をしたいときは extendの中でやる。
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'],
theme: {
colors: {
primary: '#ff6881',
},
},
};
これだとデフォルト値が上書きされるので、他の色が全部使えなくなる

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'],
theme: {
extend: {
colors: {
primary: '#ff6881',
},
},
},
};
追加したいならこう

そういえばstorybookいれたときのサンプルで satisfies
があったなあしらんなこれと思ったけどべんりそう

(・∀・)イイネ!!
satisfies の特徴は、型チェックが行われつつも、型推論結果が保持されることです。 「satisfies」(サティスファイズ)は「(条件などを)満たす、確信させる」といった意味があります。
次の colorList オブジェクトにおいて、green は ColorList の型の一部であることがチェックされ、かつ number[] 型と推論されます。配列なので、配列用メソッド map() が使えます。

appディレクトリ内でpathname使いたいときは usePathname()
を使う(next/router が使えないので next/navigation でつかう)

コンポーネント用のファイルつくるの面倒になってきたのでためしてみる

hygen generator components
で
/_template/generator/components
内のpronpt.js で設定した項目で雛形がつくれる。

Atomic Designけっこうふんわりしてるからよむ