I'm trying google sheet as a mini database with the nextJs app but how to use getStaticPaths to get specific page data. in this app I'm not using google sheet API I'm getting data as JSON.
export const getStaticPaths = async () => {
const res = await fetch('https://docs.google.com/spreadsheets/d/1OgT7pYpT__3y1qgC6Nlb8dE759drBFTSWN3H0g5M_Ps/gviz/tq?tqx=out:json')
const text = await res.text();
const data = await JSON.parse(text.substr(47).slice(0, -2));
const paths = data.table.rows.map((table) => {
return {
params: {
title: table.c[1].v
}
}
})
return {
paths,
fallback: false
}
}
export const getStaticProps = async (context) => {
const title = context.params.title;
const res = await fetch('https://docs.google.com/spreadsheets/d/1OgT7pYpT__3y1qgC6Nlb8dE759drBFTSWN3H0g5M_Ps/gviz/tq?tqx=out:json')
const text = await res.text();
const data = await JSON.parse(text.substr(47).slice(0, -2));
return {
props: { posts: data }
}
}
const Title = ({ posts }) => {
return (
<>
<div>
<h1>{ posts.table.rows[0].c[0].v }</h1>
</div>
</>
)
}
export default Title;
how to get data in dynamic page from google sheet.