困った共通処理 Next.js で、全ページ共通の処理がある場合、あんまり頭のよくないコードを書くことになります。 export const getServerSideProps = async (ctx) => { // (全ページ共通処理)共通情報を取得する。 let commonInfo; try { commonInfo = await getCommonInfo(); } catch (exception) { // 取得できなければ404で返す ctx.res.status = 404; return { props: { notFound: true } }; } // いろいろな処理… } これを全ページにコピペして書くなんて信じられな〜い! もちろん関数に抽出すればもっと短くなるかもしれないけど、 try { } catch () { return ... } は短くなら