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
ak2ie
May 27, 2023
Programming
600
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
More Decks by ak2ie
See All by ak2ie
DDDのエッセンスを取り入れたAIでの開発
ak2ie
1
280
Claude Codeはレガシー移行でどこまで使えるのか?
ak2ie
1
1.7k
SVG完全に理解してグラフ書いてみた
ak2ie
0
70
Go言語CLIツールで生産効率UPした話
ak2ie
0
130
Goではじめるバックエンド開発
ak2ie
0
90
NestJSのはじめ方
ak2ie
0
170
フロントエンドでDDDやってみた
ak2ie
0
90
初心者がシビックテックに参加してみた
ak2ie
0
140
Firebase についてとことん語りたい
ak2ie
0
130
Other Decks in Programming
See All in Programming
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
1.1k
自分的「カンファレンスの楽しみ方」
syumai
0
200
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
280
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
180
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
120
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
620
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
0
510
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
460
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
240
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.9k
Intent as Code
shoppingjaws
6
1k
A2UI for Android: Safely Rendering AI-Generated UI with Jetpack Compose - DroidKaigi 2026
itsmedreamwalker
0
140
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
1.1k
Agile that works and the tools we love
rasmusluckow
331
22k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Docker and Python
trallard
47
4.2k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
460
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
First, design no harm
axbom
PRO
2
1.3k
Statistics for Hackers
jakevdp
799
230k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
390
Paper Plane (Part 1)
katiecoart
PRO
2
11k
For a Future-Friendly Web
brad_frost
183
10k
Transcript
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で指定時間キャッシュしてくれる