'Server-side rendering not working on production Next.js
I am serving my next.js on Vercel (I tried Amplify as well). Page works but components that require data from getServerSideProps()
in my pages/index.tsx
are not required. It seems that function isn't called at all.
Could anyone help me fix this issue?
export default function Home({ cryptosData, tempObject }) {
return (
<>
{tempObject && <Converter tempObject={tempObject} />}
{cryptosData && <MainTable data={cryptosData} />}
</>
);
}
export const getServerSideProps = async () => {
const url =
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest";
const query = "?limit=80";
try {
const res = await fetch(url + query, {
headers: { "X-CMC_PRO_API_KEY": process.env.API_KEY },
});
const json = await res.json();
const data = json.data;
const [cryptosData, tempObject] = parseData(data, 40);
return {
props: { cryptosData, tempObject },
};
} catch (error) {
console.log(error);
return {
props: {},
};
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|