refactor search area - boostcampwm-2022/web33-Mildo GitHub Wiki

โœ‚๏ธ ๋ถ„๋ฐฐ๋œ ์ด์Šˆ

  • ์ง€๋„ ํด๋ฆญ์‹œ ์—ฐ๊ด€๊ฒ€์ƒ‰์–ด ๋ฆฌ์ŠคํŠธ ๋‹ซ๊ธฐ #80
  • ๊ฒ€์ƒ‰ API ํ˜ธ์ถœ ์ตœ์ ํ™” ์ˆ˜์ • #82

๐Ÿšฉ ๊ตฌํ˜„ ๋ชฉํ‘œ

  • ์ง€๋„ ํด๋ฆญ์‹œ ์—ฐ๊ด€๊ฒ€์ƒ‰์–ด ๋ฆฌ์ŠคํŠธ ๋‹ซ๊ธฐ
  • ๊ฒ€์ƒ‰ API ํ˜ธ์ถœ ์ตœ์ ํ™” useDeferredValue ๋Œ€์‹  debounce ์ ์šฉ

๐Ÿ€ ์„ธ๋ถ€ ๋ชฉํ‘œ

  • ์—ฐ๊ด€๊ฒ€์ƒ‰์–ด ๋ฆฌ์ŠคํŠธ ์ด์™ธ์˜ ๊ณณ ํด๋ฆญ ํ˜น์€ ํ„ฐ์น˜์‹œ ๋‹ซํžˆ๊ฒŒ ํ•˜๊ธฐ
    • ์—ฐ๊ด€๊ฒ€์ƒ‰์–ด ์ค„์—ฌ ์ง€๋„ ๋” ๋…ธ์ถœ์‹œํ‚ค๊ธฐ
  • ๊ฒ€์ƒ‰ API ๋‚ ๋ฆฌ๋Š” ๊ฒƒ ์ตœ์ ํ™” ํ˜„์žฌ useDeferredValue์ด์ง€๋งŒ ํ•™์Šต ํ›„ ์ข‹์€ ๊ฒƒ ์ ์šฉ

๐Ÿšง Trouble Shooting

const timer = useRef<NodeJS.Timeout | null>(null);

// let timer: NodeJS.Timeout | null = null;

...

if (timer.current) {
  clearTimeout(timer.current);
}

timer.current = setTimeout(async () => {

  setIsRelatedAreaListOpen(true);

  const { data: responseRelatedAreaInfo }: GetRelatedAreaResponseTypes =
    await apis.getRelatedAreaInfo(searchAreaName);

  setRelatedAreaInfo(responseRelatedAreaInfo);
}, 500);
  • timer๋ฅผ ์ปดํฌ๋„ŒํŠธ ์•ˆ์— let์œผ๋กœ ์„ ์–ธํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋ฉด debounce๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • useRef๋ฅผ ํ†ตํ•ด ์„ ์–ธํ•˜๋ฉด ์ž˜ ๋™์ž‘ํ•œ๋‹ค.

๐ŸŽธ ๊ธฐํƒ€

  • ์—ฐ๊ด€๊ฒ€์ƒ‰์–ด ๋ฆฌ์ŠคํŠธ๋„ ๋ชจ๋‹ฌ์ฐฝ์œผ๋กœ ๋ด๋„ ๋  ๊ฒƒ ๊ฐ™์•„ Modal ์ปดํฌ๋„ŒํŠธ๋ฅผ ์žฌํ™œ์šฉํ•ด๋ณด๋ ค ํ–ˆ์ง€๋งŒ ํฌ๊ธฐ