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; }
-