Including variable that can be calculated at build time #13019
Answered
by
Timer
jensmeindertsma
asked this question in
Help
-
If I have a value that can be calculated at build time, how do I make sure it is? Right now I'm doing the calculation just before a page function, like: let years = [2017, 2020, 2025, 1996];
years = years
.filter((year, index) => years.indexOf(year) === index)
.sort((yearA, yearB) => {
return yearA < yearB ? 1 : -1;
});
const Home = () => {
return <>{years}</> Is this the way I should do it? I know this doesn't need to go inside the page function, but where else should it go if it doesn't fit here? |
Beta Was this translation helpful? Give feedback.
Answered by
Timer
May 17, 2020
Replies: 1 comment
-
This data would be better computed within https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jensmeindertsma
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This data would be better computed within
getStaticProps
so that the code could be eliminated.https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation