2024-04-10.md

๐Ÿก

DIL: ๋ชจ๋˜ ๋ฆฌ์•กํŠธ ๋”ฅ ๋‹ค์ด๋ธŒ, 6์ฃผ์ฐจ-3

์Šคํ„ฐ๋””: ์›”๊ฐ„ CS, https://github.com/monthly-cs/2024-03-modern-react-deep-dive
์˜ค๋Š˜ ์ง„ํ–‰: ๊ฐœ์ธ๊ณต๋ถ€


DIL-week6-3_2024-04-10

| DIL ์ฃผ์ฐจ | ๋ฒ”์œ„ | ๋‚ด์šฉ | ์˜ค๋Š˜์ฐจ ์ง„๋„ | | -------- | ---------- | --------------------------------------------------------- | ----------- | | 6์ฃผ์ฐจ | 10์žฅ, 11์žฅ | ๋ฆฌ์•กํŠธ 17๊ณผ 18 ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์‚ดํŽด๋ณด๊ธฐ, Next.js 13๊ณผ ๋ฆฌ์•กํŠธ 18 | 679~682p |

์˜ค๋Š˜ ์ฝ์€ ๋‚ด์šฉ์„ markdown์œผ๋กœ ๊ฐ„๋‹จํžˆ ๋ฉ”๋ชจ
11์‹œ๋ฐ˜~12์‹œ๋ฐ˜


๋ฆฌ์•กํŠธ 18

  • ๊ฐ€์žฅ ํฐ ๋ณ€๊ฒฝ์ ์€ ๋™์‹œ์„ฑ ์ง€์›!

useId

  • ์ปดํฌ๋„ŒํŠธ๋ณ„๋กœ ์œ ๋‹ˆํฌํ•œ ๊ฐ’์„ ์ƒ์„ฑ

  • ์œ ๋‹ˆํฌํ•œ ID

    • ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ์—์„œ ์ปดํฌ๋„ŒํŠธ ID ๊ณ ์œ ์„ฑ ์œ ์ง€ํ•ด์•ผํ•จ
    • ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋žœ๋”๋ง ํ™˜๊ฒฝ์—์„œ, ํ•˜์ด๋“œ๋ ˆ์ด์…˜ ์ผ์–ด๋‚  ๋•Œ ์„œ๋ฒ„์™€ ๋™์ผํ•œ ๊ฐ’์„ ๊ฐ€์ ธ์•ผ ํ•จ
  • useId๊ฐ€ ์ƒ์„ฑํ•œ ๊ฐ’

    • :๊ฐ’:, CSS selector๋‚˜ querySelector๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๊ฒŒํ•จ
  • ์ƒ์„ฑ ์•Œ๊ณ ๋ฆฌ์ฆ˜

    • id๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํ˜„์žฌ ํŠธ๋ฆฌ์—์„œ ์ž์‹ ์˜ ์œ„์น˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 32๊ธ€์ž์˜ ์ด์ง„ ๋ฌธ์ž์—ด

    • R์€ ์„œ๋ฒ„์‚ฌ์ด๋“œ ์ƒ์„ฑ id, r์€ ํด๋ผ์ด์–ธํŠธ ์ƒ์„ฑ id

    • https://github.com/facebook/react/blob/36c908a6c85f271358ef91936df6ded18bbc6789/packages/react-reconciler/src/ReactFiberHooks.new.js#L2117-L2152

      function mountId(): string {
        ...
        const root = ((getWorkInProgressRoot(): any): FiberRoot);
        const identifierPrefix = root.identifierPrefix;
      
        let id;
        if (getIsHydrating()) { // ํ•˜์ด๋“œ๋ ˆ์ด์…˜์ด๋ผ๋ฉด? ์ฆ‰ server-generated ์ด๋ผ๋ฉด?
          const treeId = getTreeId();
      
          // Use a captial R prefix for server-generated ids.
          id = ':' + identifierPrefix + 'R' + treeId;
          // Unless this is the first id at this level, append a number at the end
          // that represents the position of this useId hook among all the useId โœ…
          const localId = localIdCounter++;
          if (localId > 0) {
            id += 'H' + localId.toString(32); // "H + 32๊ธ€์ž-์ด์ง„๋ฌธ์ž์—ด"
          }
      
          id+=':'; // ๋งˆ์ง€๋ง‰ : ๋ถ™์ด๊ธฐ
        } else {
          // Use a lowercase r prefix for client-generated ids.
          const globalClientId = globalClientIdCounter++;
          id = ':' + identifierPrefix + 'r' + globalClientId.toString(32) + ':';
        }
      
        hook.memoizedState = id;
        return id;
      }