Closed pitang1965 closed 2 years ago
ブログやポートフォリオの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);
@XNCOAISN 今回は三項演算子を採用してみました。
7 を分離
ブログやポートフォリオのletを使用している場所 letを使わない書き方
useMemoを使う方法
即時実行関数を使う方法
三項演算子を使う方法