我相信代码库一定是设置错误,但我不能确定我在下一个js中使用getStaticProps时没有遵循什么约定
Link to codesandbox.io project
// Page Component, receiving allPokemons
// from getStaticProps
export default function Home({ allPokemons }) {
return (
<ul>
{ /* mapping all the data inside
an unordered list */}
{allPokemons.map((poke) => (
<li key={poke.url}>{poke.name}</li>
))}
</ul>
);
}
export async function getStaticProps() {
// Call the fetch method and passing
// the pokeAPI link
const response = await fetch(
'https://pokeapi.co/api/v2/pokemon/');
// Parse the JSON
const data = await response.json();
// Finally we return the result
// inside props as allPokemons
return {
props: { allPokemons: data.results },
};
}
我期待着这将产生一个口袋妖怪名单每此https://www.geeksforgeeks.org/next-js-getstaticprops-function/
1条答案
按热度按时间wnvonmuf1#
问题是_app. js文件禁止getStaticProps工作https://nextjs.org/docs/advanced-features/custom-app