Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Notion APIと学ぶNext.js
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ak2ie
May 27, 2023
Programming
610
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Notion APIと学ぶNext.js
「にかくほめる!マウントなしのLT会」での発表内容です。
NotionをCMSとしてブログ作成を例に、Next.js(ver. 13)の機能説明をしました。
ak2ie
May 27, 2023
Transcript
18 slides
Notion APIと学ぶNext.js 2023/05/27
自己紹介 • 名前:ak2ie • 職業:Webエンジニア • 好きなもの:コーヒー
目次 1. Next.jsとは? 2. ページの作り方 a. URLパラメータ、ローディング、リンク 3. fetch API
a. データ取得 b. 再検証
Next.js • Reactをベースにしたフロントエンドフレームワーク • ルーティングが簡単 • スタイル設定もできる • ver. 13での動作を説明します
ブログ • 記事 ◦ Notionで書く ◦ URLは/articles/****で自由に設定可能 • 固定ページもある
Notion
App Router • ページはapp内にディレクトリを作り、 page.tsxを置く • https://example.com/articles • ver. 12以前はpagesディレクトリを使っていた
app page.tsx articles
URLパラメータの取得 • ディレクトリ名を”[“, “]”で囲む • propsからパラメータを取得できる https://example.com/articles/title const Articles =
async ({ params: { slug } }: Props) => { return <p>slug</p> } app page.tsx articles [slug]
ローディング • page.tsxと同じディレクトリに ”loading.tsx”を置くだけ • 読み込み中だけ表示される app/articles/loading.tsx export default function
Loading() { return <p className="p-2">Loading...</p> } app page.tsx articles loading.tsx
Not Found • app/not-found.tsxに書く export default function NotFound() { return
<p className="p-2">ページが存在しません</p> } • notFound()を呼んで、リダイレクトもできる import { notFound } from "next/navigation"; notFound(); app not-found.tsx
リンク • Next.js 13より、<Link>内に<a>タグは不要 ver. 13 <Link href="/about">About</Link> ver. 12以前
<Link href="/about"><a>About</a></Link>
データ取得 • fetch APIで取得できる • JavaScriptのAPIをNext.js が独自に拡張 const response =
await fetch( `https://example.com`, { headers: { Authorization: `Bearer ABC`, "Content-Type": "application/json", "Notion-Version": "2022-06-28", }, } );
Notion データベース • Notion内でデータを管理 する方法 • Viewを切り替えること で、見え方を変えられる
Notion Page • Notion内でテキストや画像をまとめる ところ • リンクやコードも書けて、総称して「ブ ロック」と呼ばれる ブロック ブロック
Notion API • Notion データベースやブロックを取得可能 ブロックを取得するコード例 const response = await
fetch( `https://api.notion.com/v1/blocks/ ${pageId}/children` , { headers: { Authorization: `Bearer ${process.env.NOTION_SECRET !}`, "Content-Type" : "application/json" , "Notion-Version" : "2022-06-28" , }, } );
再検証(revalidate) • fetchしたデータは、指定した時間まで キャッシュされる • 時間経過後のアクセス時に再取得される アクセス 指定時間後までキャッシュ キャッシュ アクセス
データ再取得 時間 キャッシュを返 す await fetch( next: { revalidate: 30, },
Server/Client Component • サーバーとクライアント(ブラウザ)どちらでレンダリングするか • サーバーの方が高速 • Server Component ◦
基本的にこちら • Client Component ◦ クリックイベントなどブラウザでしか扱えないもの
Next.jsまとめ • appディレクトリにページを作る ◦ ディレクトリを作って、page.tsxを置く ◦ app/[slug]/page.tsx => propsから取得可 ◦
app/not-found.tsx: Not Foundページ • fetch API ◦ JavaScript APIをNext.jsが拡張 ◦ revalidateで指定時間キャッシュしてくれる
More Decks by ak2ie
See All by ak2ie
LambdaなのにVM?Lambda MicroVMsを調べてみた / About Lambda Micro VMs
ak2ie
2
73
DDDのエッセンスを取り入れたAIでの開発
ak2ie
1
320
Claude Codeはレガシー移行でどこまで使えるのか?
ak2ie
1
1.7k
SVG完全に理解してグラフ書いてみた
ak2ie
0
76
Go言語CLIツールで生産効率UPした話
ak2ie
0
140
Goではじめるバックエンド開発
ak2ie
0
96
NestJSのはじめ方
ak2ie
0
180
フロントエンドでDDDやってみた
ak2ie
0
95
初心者がシビックテックに参加してみた
ak2ie
0
140
Other Decks in Programming
See All in Programming
はじめてのPLATEAU
nokonoko1203
1
660
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
360
オーケストレーション記述言語 Katari
yukikurage
0
270
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
420
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
360
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
160
SODA - FACT BOOK(EN)
sodainc
1
270
Ruby から Emacs を操作したい
phigasui
0
360
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
210
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
260
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
310
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
570
YesSQL, Process and Tooling at Scale
rocio
174
15k
How to Talk to Developers About Accessibility
jct
2
620
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
The Language of Interfaces
destraynor
162
27k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
480
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
620
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Navigating Team Friction
lara
192
16k