Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tatsuya19881021レビュー:getStaticPropsの例外補足時の戻り値 #32

Open
pitang1965 opened this issue Aug 31, 2022 · 2 comments

Comments

@pitang1965
Copy link
Owner

#30 を転記しました。@tatsuya19881021

  • getStaticProps関数のcatch処理。
    • returnのデータ構造は正しい?
    return {
      props: {
        err: 'データ取得で問題が発生しました。',
      },
    };

↓ 下記のような、data を入れなくても問題無いか?↓

    return {
      props: {
        data: {
          err: 'データ取得で問題が発生しました。',
        },
      },
    };
@pitang1965
Copy link
Owner Author

これどうなのでしょうか?調べたら次の記述もありました。

https://stackoverflow.com/questions/67168743/how-to-cleanly-handle-errors-in-nextjs-getstaticprops

export const getStaticProps = async () => {
  try {
    const { data, errors } = await someQuery();
    if (errors || !data) {
      return { notFound: true };
    }
    return { props: { data } };
  } catch () {
    return { notFound: true };
  }
};

@tatsuya19881021
Copy link

なるほどー。動作上、問題ないなら良いと思ってますが…
書き方は難しいですね〜。

単純にエラー時の挙動がおかしくないか?ってのだけ気になりました🙇

@pitang1965 pitang1965 changed the title tatsuya19881021レビュー:日付書式の関数 tatsuya19881021レビュー:getStaticPropsの例外補足時の戻り値 Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants