前提
現在下記の動画を参考にして、
firestoreのデータからダイナミックルーティングのページを生成しようとしています。
下記の動画の構造を真似して、firestore版に変えています。
参考動画
https://www.youtube.com/watch?v=mAHqpdVzJmA
実現したいこと
https://firestore.googleapis.com/v1/projects/next-auth-app-2aa40/databases/(default)/documents/posts
のfirestoreのデータからidを取得して、ダイナミックルーティングのページを生成(posts/[id].tsx)をしたい
発生している問題・エラーメッセージ
ですが、現状だとyarn build時にエラーが出てしまいます。
> Build error occurred TypeError: data.map is not a function at getStaticPaths (/Users/abeshmupeii/manga-kousatu.net/.next/server/pages/posts/[id].js:23:24) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async buildStaticPaths (/Users/abeshmupeii/manga-kousatu.net/node_modules/next/dist/build/utils.js:491:31) at async /Users/abeshmupeii/manga-kousatu.net/node_modules/next/dist/build/utils.js:632:119 at async Span.traceAsyncFn (/Users/abeshmupeii/manga-kousatu.net/node_modules/next/dist/trace/trace.js:79:20) { type: 'TypeError' }
const paths = data.map((post) => { return { params: { id: post.id.toString() }, }; });
にidがうまく入らないのが原因だと考えています。
全体のデータ自体は取得できる状態です。
対処法があれば教えて頂きたいです。
よろしくお願いします。
javaScript
JavaScript
1export const getStaticPaths = async () => { 2 const res = await fetch( 3 "https://firestore.googleapis.com/v1/projects/next-auth-app-2aa40/databases/(default)/documents/posts" 4 ); 5 const data = await res.json(); 6 7 const paths = data.map((post) => { 8 return { 9 params: { id: post.id.toString() }, 10 }; 11 }); 12 13 return { 14 paths, 15 fallback: false, 16 }; 17}; 18 19export const getStaticProps = async (context) => { 20 const id = context.params.id; 21 const res = await fetch( 22 "https://firestore.googleapis.com/v1/projects/next-auth-app-2aa40/databases/(default)/documents/posts" + 23 id 24 ); 25 const data = await res.json(); 26 27 return { 28 props: { 29 post: data, 30 }, 31 }; 32}; 33 34const Daitails = ({ post }) => { 35 return ( 36 <div> 37 <h1>{post.title}</h1> 38 </div> 39 ); 40}; 41 42export default Daitails; 43 44
試したこと
12月31日
補足情報(FW/ツールのバージョンなど)
ソースコード

回答3件
あなたの回答
tips
プレビュー