From 811471499654bca3e91158157fd22e5b064d6a03 Mon Sep 17 00:00:00 2001 From: Damla Koksal Date: Sat, 23 Apr 2022 11:05:05 +0300 Subject: [PATCH] [#3]feat: memoize ellipsed username --- src/components/layouts/Dashboard/modules/Nav/Nav.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/layouts/Dashboard/modules/Nav/Nav.tsx b/src/components/layouts/Dashboard/modules/Nav/Nav.tsx index 75274ca..7362b00 100644 --- a/src/components/layouts/Dashboard/modules/Nav/Nav.tsx +++ b/src/components/layouts/Dashboard/modules/Nav/Nav.tsx @@ -3,7 +3,7 @@ import Image from 'next/image'; import { LogoutIcon, MenuIcon, XIcon } from '@heroicons/react/outline'; import Link from 'next/link'; import { useRouter } from 'next/router'; -import { useEffect } from 'react'; +import { useEffect, useMemo } from 'react'; import { useMoralis } from 'react-moralis'; import { APP_NAME } from '../../../../../utils/constants'; import { getEllipsesText } from '../../../../../utils/utils'; @@ -13,6 +13,7 @@ import { Icons } from '../../../../common/Icon/Icon'; const Nav = () => { const { isAuthenticated, logout, user } = useMoralis(); const router = useRouter(); + const ethAddress = user?.get('ethAddress'); const navigation = [ { name: '🧾 Transactions', href: '#' }, @@ -30,6 +31,11 @@ const Nav = () => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [isAuthenticated]); + const ellipsedUserName = useMemo( + () => ethAddress && getEllipsesText(ethAddress), + [ethAddress] + ); + return ( {({ open }) => ( @@ -77,7 +83,7 @@ const Nav = () => { />
- {getEllipsesText(user?.get('ethAddress'))} + {ellipsedUserName}