pitang1965 / next-portfolio

各種APIを用いた自己紹介サイト(しまぶーサロンのチーム開発課題)
https://pitang1965-next-portfolio.vercel.app/
0 stars 1 forks source link

XNCOAISNレビュー:letの使用について #10

Closed pitang1965 closed 2 years ago

pitang1965 commented 2 years ago

7 を分離

ブログやポートフォリオのletを使用している場所 letを使わない書き方

useMemoを使う方法

const numberToShow = useMemo(() => {
  if (router.pathname === '/') {
    return isMobileUi ? 4 : 5;
  } else {
    return isMobileUi ? 5 : 10;
  }
}, [router, isMobileUi]);

即時実行関数を使う方法

const numberToShow = (() => {
  if (router.pathname === '/') {
    return isMobileUi ? 4 : 5;
  } else {
    return isMobileUi ? 5 : 10;
  }
})();

三項演算子を使う方法

const numberToShow =
    router.pathname === "/" ? (isMobileUi ? 4 : 5) : (isMobileUi ? 5 : 10);
pitang1965 commented 2 years ago

@XNCOAISN 今回は三項演算子を採用してみました。