๐Ÿ›’ ์‡ผํ•‘๋ชฐ ํด๋ก ์ฝ”๋”ฉ์„ ํ•˜๋ฉฐ ๋ฐฐ์šด ๊ฒƒ๋“ค #1

์›์ง€ยท2022๋…„ 12์›” 8์ผ
1

์Šคํ„ฐ๋”” ํšŒ๊ณ 

๋ชฉ๋ก ๋ณด๊ธฐ
2/5
post-thumbnail

๋ฆฌ์•กํŠธ ๊ณต๋ถ€๋ฅผ ์‹œ์ž‘ํ•˜๊ณ  ์Šคํ„ฐ๋””์›๋“ค๊ณผ ์Šคํ† ์–ดํŒœ (https://smartstore.naver.com/freshmentor) ํด๋ก ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ํฌ์ŠคํŠธ๋Š” ์Šคํ„ฐ๋””๋ฅผ ์ง„ํ–‰ํ•˜๋ฉฐ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์ ๊ณผ ํ•ด๊ฒฐ๊ณผ์ •์„ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค !

์ผ๋‹จ 1์ฐจ์ ์œผ๋กœ ์ด๋ฒˆ ํด๋ก ์ฝ”๋”ฉ์—์„œ ์ œ๊ฐ€ ๋งก์€ ๋ถ€๋ถ„์€ Header์™€ GNB์˜€์Šต๋‹ˆ๋‹ค. ์–ด๋ ต์ง€ ์•Š๊ฒŒ ์ฝ”๋“œ๋ฅผ ์งค ์ˆ˜ ์žˆ์„ ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์ง€๋งŒ ์ด์ œ ๋ง‰ ๋ฆฌ์•กํŠธ ๊ณต๋ถ€๋ฅผ ์‹œ์ž‘ํ•œ ์ €์—๊ฒŒ๋Š” ์˜ˆ์ƒ์™ธ๋กœ ์–ด๋ ค์›€์ด ๋งŽ์•˜๋Š”๋ฐ์š” .. ๐Ÿฅฒ

1. ๋นˆ๋ฐฐ์—ด์€ ์–ด๋–ป๊ฒŒ map์„ ๋Œ๋ฆฌ์ง€ ?

์ฒซ๋ฒˆ์งธ ๋ฌธ์ œ๋Š” GNB์—์„œ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. GNB์˜ one depth๋Š” ๋งต์„ ๋Œ๋ ค ์ˆ˜์›”ํ•˜๊ฒŒ ๋งŒ๋“ค์—ˆ์ง€๋งŒ two depth๋Š” ์ถ•์‚ฐ๋ฌผ, ์‹ํ’ˆ๋ช…์ธ ์นดํ…Œ๊ณ ๋ฆฌ์™€ ๊ฐ™์ด ํ•˜์œ„ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์—†๋Š” ํ•ญ๋ชฉ์ด ์žˆ์—ˆ์–ด์š”.

GNB๋ฅผ ํ™•์ธํ•˜๊ธฐ ์ „์—๋Š” 'one depth๋ฅผ map์œผ๋กœ ๋Œ๋ฆฌ๊ณ  tow depth๋„ map์œผ๋กœ ๋Œ๋ ค ๋‘ ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ํ•ฉ์น˜๋ฉด ๋˜๊ฒ ๋‹ค!' ์ƒ๊ฐํ–ˆ์—ˆ๋Š”๋ฐ์š” ํ•˜์œ„์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์—†๋Š” ํ•ญ๋ชฉ์€ ๋ณ€์ˆ˜๋ฅผ ์–ด๋–ป๊ฒŒ ์งœ์•ผํ•˜์ง€ ..? ์–ด๋ ต๋”๋ผ๊ณ ์š” ใ…œใ…œ

const LINKS = [
    { mainLink: '๋ฒ ์ŠคํŠธ', subLink: null },
    {
      mainLink: '๋†์‚ฐ๋ฌผ',
      subLink: ['๊ณผ์ผ', '์ฑ„์†Œ', '๊ณก๋ฌผ'],
    },
    { mainLink: '์ˆ˜์‚ฐ๋ฌผ', subLink: ['์ œ์ฒ ', '๊ฑด์–ด๋ฌผ'] },
    { mainLink: '์ถ•์‚ฐ๋ฌผ', subLink: null },
    {
      mainLink: '๊ฐ€๊ณต์‹ํ’ˆ',
      subLink: ['์ผ๋ฐ˜', '๋ฐ˜์ฐฌ', '์ฐจ๋ฅ˜', '๋ฒŒ๊ฟ€', '๊ฐ„ํŽธ๊ฐ„์‹'],
    },
    { mainLink: '์ „์ฒด์ƒํ’ˆ', subLink: null },
  ];

๊ทธ๋Ÿฐ๋ฐ ์˜ˆ์ƒ์™ธ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ null๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋˜๋Š” ๊ฑฐ ์˜€์–ด์š”. ์ด๋ ‡๊ฒŒ LINKS ๋ณ€์ˆ˜๋ฅผ ์งœ๊ณ 

props.category.subCategory?.map((categoryItem, i)=>{
           return <Link key={i}>{categoryItem}</Link>
         })

์˜ต์…”๋„ ์ฒด์ด๋‹์œผ๋กœ map์„ ๋Œ๋ฆฌ๋ฉด null์ผ ๋•Œ๋Š” ๋ถˆํ•„์š”ํ•œ ํ•˜์œ„ ์š”์†Œ๋ฅผ ๋งŒ๋“ค์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— two depth๋ฅผ ๋ฌด์‚ฌํžˆ ์งค ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์‹ค ์ด๋ฒˆ์— GNB๋ฅผ ๋งŒ๋“ค๋ฉฐ ์˜ต์…”๋„ ์ฒด์ด๋‹ ๊ฐœ๋…์„ ์ฒ˜์Œ ์•Œ๊ฒŒ๋˜์—ˆ๋Š”๋ฐ์š”

๐Ÿ”Ž ์˜ต์…”๋„ ์ฒด์ด๋‹์ด๋ž€ ?

์ฐธ์กฐ๊ฐ€ย nullish (null ๋˜๋Š” undefined)์ผ ๊ฒฝ์šฐ, ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๋Œ€์‹  ํ‘œํ˜„์‹์˜ ๋ฆฌํ„ด ๊ฐ’์„ undefined๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ๋ฒ•์ž…๋‹ˆ๋‹ค.

โ€˜?.โ€™๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์˜ต์…”๋„ ์ฒด์ด๋‹ ๋•๋ถ„์— null ๊ฐ’์ด ์žˆ๋Š” ๊ฐ์ฒด๋ฅผ ๋ฌธ์ œ์—†์ด map์œผ๋กœ ๋Œ๋ ค ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

2. ๊ทธ๋ƒฅ querySelector ์“ฐ๋ฉด ์•ˆ๋ ๊นŒ์š” ..?

๋‘ ๋ฒˆ์งธ๋กœ๋Š” ์–ด๋ ค์›€์„ ๊ฒช์€ ๋ถ€๋ถ„์€ two depth์˜ ์ „์ฒด ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ํ˜ธ๋ฒ„ํ•  ๊ฒฝ์šฐ ํ•œ ๋ฒˆ์— ๋œจ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ

์ด๋ ‡๊ฒŒ ๊ฐœ๋ณ„์ ์œผ๋กœ ๋œจ๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜€๋‹ค๋ฉด querySelector, getElementById ๋“ฑ์„ ์จ์„œ ์ง์ ‘ ๋”์š”์†Œ๋ฅผ ์„ ํƒํ•ด ์ฝ”๋“œ๋ฅผ ์งœ ๋ฌด์ง€ ์‰ฌ์› ์„ํ…๋ฐ์š” .. ๋ฆฌ์•กํŠธ๋Š” virtual DOM์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋Ÿด ์ˆ˜ ์—†์–ด ๋‹ต๋‹ตํ•œ ๋ถ€๋ถ„์ด ๋งŽ์•˜์Šต๋‹ˆ๋‹ค.

๐Ÿ”Ž ๊ทธ๋Ÿฐ๋ฐ ๋ฆฌ์•กํŠธ์—์„œ๋Š” ์™œ ์ง์ ‘ DOM ์š”์†Œ๋ฅผ ์„ ํƒํ•˜๋ฉด ์•ˆ๋ ๊นŒ์š” ?

๋ฐ”๋กœ document.querySelector์™€ ๊ฐ™์€ css ์„ ํƒ์ž๋กœ ์š”์†Œ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ๊ฒฝ์šฐ, ์‹ค์ œ DOM์˜ ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์ „์—ญ ์…€๋ ‰ํ„ฐ๋Š” ์ฝ”๋“œ๋ฅผ ์“ด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์•„๋‹Œ ์ „์ฒด document๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์ œ๊ฐ€ ์›ํ•˜๋Š” ํŠน์ • DOM ์ด ์•„๋‹Œ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์— ์žˆ๋Š” DOM ์— ์ ‘๊ทผํ• ์ง€๋„ ๋ชจ๋ฅธ๋‹ค๋Š” ๊ฒƒ ..

๋”ฐ๋ผ์„œ ์šฐ๋ฆฌ๋Š” state๋ฅผ ์‚ฌ์šฉํ•ด ๋‚ด๋ถ€ ์š”์†Œ๋ฅผ ์ œ์–ดํ•ด์•ผํ•˜๋Š”๋ฐ์š” .. ์ €๋Š” ์ด state์˜ ๊ฐœ๋…์ด ์™€๋‹ฟ์ง€๊ฐ€ ์•Š์•„ ์ฝ”๋“œ๋ฅผ ์งœ๋Š” ๊ฒƒ์ด ์–ด๋ ค์› ์Šต๋‹ˆ๋‹ค.

const [isHovering, setIsHovering] = useState(false);
const [targetGnb, setTargetGnb] = useState('');

๋จผ์ € GNB๋ฅผ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•ด์„œ useState ํ›…์„ ์‚ฌ์šฉํ•ด ๋งˆ์šฐ์Šค๋ฅผ ํ˜ธ๋ฒ„ํ–ˆ์„ ๋•Œ์˜ ์ƒํƒœ๊ฐ’์„ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•œ isHovering, ํƒ€์ผ“์ด ๋œ GNB ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•œ targetGnb ๋ณ€์ˆ˜ ๋‘ ๊ฐœ๋ฅผ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.


const handleMouseOver = (e) => {
    setIsHovering(true);
    if(e.target.nodeName === 'A'){
      setTargetGnb(e.target.dataset.categoryItem)
    } 
  	console.log(targetGnb)
  };

handleMouseOver ํ•จ์ˆ˜๋Š” GNB์— onMouseOver๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์ž‘๋™ํ•˜๋Š” ํ•จ์ˆ˜๋กœ ๋จผ์ € IsHovering์˜ ์ƒํƒœ๋ฅผ true๋กœ ๋งŒ๋“ค๊ณ  targetGnb๋ฅผ ์„ ํƒ๋œ ์š”์†Œ์˜ data-category-item์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค. ํ˜ธ๋ฒ„ ๋์„ ๋•Œ ํ•ด๋‹น node์˜ ์ด๋ฆ„์ด A๋ผ๋ฉด targetGnb๋ฅผ dataset.catetoryItem์œผ๋กœ ๋ฐ›์•„์„œ targetGnb๋ฅผ ์—…๋ฐ์ดํŠธ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

targetGnb๊ฐ€ ์˜ˆ์ƒ๋Œ€๋กœ ์ž˜ ์—…๋ฐ์ดํŠธ ๋˜๊ณ  ์žˆ๋Š”์ง€ ์ฝ˜์†”์— ์ค‘๊ฐ„์ค‘๊ฐ„ ์ฐ์–ด๋ณด๋ฉฐ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค !

์–ด๋ผ๋ผ ๊ทธ๋Ÿฐ๋ฐ ๋ง์ด์ฃ  ..

์ฝ˜์†”์—๋Š” targetGnb์˜ ์ด์ „ ๊ฐ’์ด ์ถœ๋ ฅ๋˜๊ณ  ์—…๋ฐ์ดํŠธ ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ–ˆ์Šต๋‹ˆ๋‹ค ^^

๋ฌธ์ œ๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€ ๋ณด์•„ํ•˜๋‹ˆ .. console.log(targetGnb)์˜ ์œ„์น˜๊ฐ€ ์ž˜๋ชป๋˜์—ˆ๋”๋ผ๊ณ ์š”.

useState๋Š” state ๊ฐ’์˜ ๋ณ€ํ™”๋ฅผ ๊ฐ์ง€ํ•˜๊ณ , ๋ฆฌ์•กํŠธ๋Š” state๊ฐ€ ๋ณ€ํ™”ํ•˜์˜€์„ ๋•Œ ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฆฌ๋žœ๋”๋ง ํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ handleMouseOver ํ•จ์ˆ˜ ๋‚ด์—์„œ ์ฝ˜์†”์— targetGnb ๊ฐ’์„ ์ฐ๊ฒŒ ๋  ๊ฒฝ์šฐ, ์ „์ฒด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋‹ค์‹œ ํ˜ธ์ถœ๋˜๊ธฐ ์ „์ด๊ธฐ ๋•Œ๋ฌธ์— ์—…๋ฐ์ดํŠธ๊ฐ€ ๋˜์ง€ ์•Š์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค. ๋ณ€๊ฒฝ๋œ targetGnb ๊ฐ’์„ ํ™•์ธํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด handleMouseOver ํ•จ์ˆ˜ ๋ฐ–์—์„œ console.log(targetGnb)์„ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ˆ˜์ •ํ•˜๊ณ  ์ฝ˜์†”์„ ํ™•์ธํ•ด๋ณด๋‹ˆ targetGnb๊ฐ€ ๋“ค์–ด์˜ค๊ณ  ์žˆ๊ตฐ์š” ๐Ÿ‘

{
        props.category.mainCategory === props.targetGnb ? 
        props.category.subCategory && props.category.subCategory.map((categoryItem, i)=>{
                    return <Link key={i}>{categoryItem}</Link>
                  }) : ''
      }

์ด์ œ targetGnb์™€ GNB์—์„œ ์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ๊ฐ™์„ ๊ฒฝ์šฐ์— two depth ํ•ญ๋ชฉ์œผ๋กœ map์„ ๋Œ๋ฆฝ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ two depth๋ฅผ ๋งต์œผ๋กœ ๋Œ๋ฆฌ๋ฉด

์งœ์ž” ! ์ด๋ ‡๊ฒŒ targetGnb์— ํ•ด๋‹นํ•˜๋Š” two depth ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ul ๋ฐ•์Šค๊ฐ€ ํ•ด๋‹น๋˜๋Š” targetGnb ์ผ ๋•Œ๋งŒ ๋œจ๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ๋ชจ๋“  ul์ด ํ•œ ๋ฒˆ์— ๋œจ๊ณ  ์žˆ๋„ค์š” .. ^^

{props.links.subLink && props.links.mainLink === props.targetGnb ? (<ul className={style.twoDep} data-main={props.targetGnb}>
      {
        props.links.mainLink === props.targetGnb ? 
        props.links.subLink && props.links.subLink.map((link, i)=>{
          return <li key={i} className={selected === i ? style.selectedList : style.list} onMouseOver={()=>{handleMouseOver(i); console.log(selected)}}><Link className={style.link} to={`/category/${link}`} key={i}>{link}</Link></li>
        }) : ''
      }
    </ul>) : ''}

์ด ๋ฌธ์ œ๋Š” li์— map์„ ๋Œ๋ฆฌ๋Š” ์กฐ๊ฑด์„ ul์—๋„ ๋˜‘๊ฐ™์ด ์„ค์ •ํ•ด์คฌ๋”๋‹ˆ ๊ธˆ์ƒˆ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค !

3. ์˜์—ญ ์„ค์ •์„ ๋ช…ํ™•ํžˆ !


one depth์€ ๋ฌด์‚ฌํžˆ ๊ตฌํ˜„์ด ๋˜์—ˆ์ง€๋งŒ two depth ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ํด๋ฆญํ•˜๋ ค๊ณ  ํ•˜๋ฉด li๋“ค์ด ๋ชจ๋‘ ์‚ฌ๋ผ์ ธ๋ฒ„๋ฆฌ๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค .. ์ด์œ ๊ฐ€ ๋ฌด์—‡์ผ๊นŒ ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ

const handleMouseOver = (e) => {
    setIsHovering(true);
    if(e.target.nodeName === 'A'){
      setTargetGnb(e.target.dataset.categoryItem)
    } 
  };

targetGnb๊ฐ€ ๋…ธ๋“œ๋„ค์ž„์ด A์ผ ๋•Œ๋งŒ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋˜์–ด ํ•ด๋‹น๋œ ์˜์—ญ์„ ๋ฒ—์–ด๋‚˜๋ฉด targetGnb๊ฐ’์ด ์‚ฌ๋ผ์ง€๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

const handleMouseOver = (e) => {
    if(!e.target.dataset.link) return
    setTargetGnb(event.target.dataset.link)
  };

๋”ฐ๋ผ์„œ e.target.dataset.link ๊ฐ’์ด ์—†์„ ๋•Œ๋Š” ํ•จ์ˆ˜๋ฅผ ์ข…๋ฃŒํ•˜์—ฌ ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์ด์ „์˜ targetGnb๊ฐ’์„ ๊ณ„์† ๊ฐ€์ง€๊ณ  ์žˆ๋„๋ก ์ˆ˜์ •ํ•˜๊ณ , setTargetGnb์˜ ์˜์—ญ์„ ์ถ•์†Œํ•˜๋˜ if๋ฌธ์„ ์ง€์šฐ๋‹ˆ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

4. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์—์„œ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์“ฐ๋Š” ๊ฒฝ์šฐ๋Š” ?

๋‹ค์Œ ๋ฌธ์ œ๋Š” tow depth ๊ฐ๊ฐ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ ๋ฐฐ๊ฒฝ์ƒ‰๊ณผ ๊ธ€์”จ์ƒ‰์„ ๋ฐ”๊พธ๋Š” handleMouseOver ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

one depth์—์„œ onMouseOver ์ด๋ฒคํŠธ๋ฅผ ์‹คํ–‰ํ–ˆ๋˜ ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ handleMouseOver(i) ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์ž

Unhandled Thrown Error!
Too many re-renders. React limits the number of renders to prevent an infinite loop.

์œ„์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‚ด์šฉ์„ ๋ณด๋‹ˆ ๋„ˆ๋ฌด ๋งŽ์€ ๋ฆฌ๋ Œ๋”๊ฐ€ ์ผ์–ด๋‚˜๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์ด์—ˆ๋Š”๋ฐ์š”..

  <li onMouseOver={handleMouseOver}>
  	{link}
  </li>

one depth ์—์„œ๋Š” ์ด๋ ‡๊ฒŒ handleMouseOver ํ•จ์ˆ˜ ์ž์ฒด๋ฅผ ์ „๋‹ฌํ•ด๋„ ๋ฌธ์ œ๊ฐ€ ์—†์—ˆ๋Š”๋ฐ ์™œ two depth์—์„œ๋Š” ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๊ฑธ๊นŒ์š” ?

<li onMouseOver={handleMouseOver(i)}>
  {link}
</li>

๋ฐ”๋กœ two depth์˜ ๊ฒฝ์šฐ, i๋ผ๋Š” ์ธ์ž๋ฅผ ๋„˜๊ฒจ์ฃผ๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์—ˆ์Šต๋‹ˆ๋‹ค. ์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด ํ•จ์ˆ˜ ์ž์ฒด๊ฐ€ ์ „๋‹ฌ๋˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ํ˜•ํƒœ๊ฐ€ ๋˜์–ด๋ฒ„๋ฆฝ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ onMouseOver์™€ ๊ด€๊ณ„์—†์ด ๋ฐ”๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

<li onMouseOver={()=>{handleMouseOver(i)}>
  {link}
</li>

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฒคํŠธ ํ•จ์ˆ˜์— ์ธ์ž๋ฅผ ์ „๋‹ฌํ•ด์•ผํ•  ๊ฒฝ์šฐ, ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ํ•ด๋‹น ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ๋ถ€์—์„œ ์ธ์ž๋ฅผ ๋„˜๊ฒจ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€