next.js getStaticProps返回未定义的结果

yrwegjxp  于 2023-04-20  发布在  其他
关注(0)|答案(1)|浏览(155)

我相信代码库一定是设置错误,但我不能确定我在下一个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/

相关问题