React 19 °ú React.Compiler
ÀÌ ±ÛÀÌ ÀÛ¼ºµÇ°í ÀÖ´Â 2024.05.30 ½ÃÁ¡¿¡¼, React Conference 2024 °¡ ÇÖÇÕ´Ï´Ù.
ÄÁÆÛ·±½º¿¡¼´Â React 19 ÀÌ ¾ðÁ¦ ¹ßÇ¥µÉÁö ±â´ë¸¦ ¸ðÀ¸°í Àִµ¥¿ä,
RC 2024 ¿¡¼ Áö±Ý °¡Àå ÇÖ ÇÑ °ü½ÉÀº React Compiler ÀÎ °Í °°°í, React Compiler ´Â °¡Àå ÇÖÇÑ À̽´°¡ µÇ¾î¼ ´Ù¸¥ ¸ðµç À̽´µéÀ» ºí·¢È¦Ã³·³ »¡¾ÆµéÀÌ°í ÀÖ´Â °Í °°½À´Ï´Ù.
React 19 ´Â, ¿Ã °¡À» Âë¿¡ Á¤½Ä °ø°³µÉ ¿¹Á¤À¸·Î ¾Ë·ÁÁ® ÀÖÁÒ.
Meta ´Â ÀÌ¹Ì ¸î ´Þ Àü¿¡, React 19 ¿¡´Â React-Compiler °¡ Æ÷ÇÔµÇÁö ¾Ê´Â´Ù°í, °ø½Ä Æ®ÀÀ» ÅëÇØ ¸ø¹Ú¾Æ µ×´ø ¹Ù Àִµ¥¿ä,
±×¸®°í ¿Ã ¿¬¸»Âë, ¸¶ÀÌ³Ê ¾÷±×·¹À̵忡¼ React-Compiler °¡ Ãß°¡µÉ °ÍÀ¸·Î ¿¹»óµÇ°í ÀÖ¾ú½À´Ï´Ù.
ÇÏÁö¸¸ React-Compiler ¿¡ ´ëÇÑ ±â´ë°¡ ¿ö³« Ä¿Á®¼ Àϱî¿ä.. RC 2024 ¿¡¼ »ç¶÷µéÀÇ °ü½ÉÀº React-Compiler ·Î ½ò¸®°í ÀÖ´Â °Í °°½À´Ï´Ù.
±×·¡¼, React-Compiler ¿¡ °üÇÑ Á¦ Á¤º¸¿Í »ý°¢À» Á¶±ÝÀ̳ª¸¶ °øÀ¯Çغ¸·Á°í ÇÕ´Ï´Ù.
React ¿¡¼´Â ¸ðµç ¸®·»´õ¸µÀ» ºñ¿ëÀ¸·Î º¸±âµµ ÇÏÁÒ. ¸®·»´õ¸µ°ú ¿¬»êÀÇ ¹«ÀǹÌÇÑ ¹Ýº¹À» ÇÇÇϱâ À§ÇØ React 18 ¿¡¼´Â ¸Þ¸ðÀÌÁ¦ÀÌ¼Ç ±â¹ýÀ» »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù.
¹®Á¦´Â ÀÌ°Ô ¹ø°Å·Ó±âµµ ÇÏ°í °¡µ¶¼ºÀ» ¹æÇØÇÑ´Ù´Â Á¡Àε¥, ÀÌ ¶§¹®¿¡ memoization ÀÇ ¹Ý´ëµÇ´Â °³³äÀ¸·Î, React.Forget À̶ó´Â ¾ÆÀ̵ð¾î°¡ µîÀåÇϱ⵵ Çß½À´Ï´Ù. ¸®¾×Æ®ÀÇ build.time ¿¡ react.memo ¸¦ ¾Ë¾Æ¼ ó¸®ÇØÁÖ°Ú´Ù´Â »ý°¢ÀÌÁÒ.
React.Compiler °¡ ÁÖ¸ñÀ» ¹Þ°í ÀÖ´Â µ¥¿¡´Â ÀÌ·± ¹è°æÀÌ ÀÖ¾ú½À´Ï´Ù.
React 19 ¿¡ React.Compiler °¡ Æ÷ÇÔµÉÁö´Â ¾ÆÁ÷ ¾Æ¹«µµ ¾Ë ¼ö ¾ø½À´Ï´Ù.
React.Compiler ´Â ¾ÆÁ÷ Á¤½Ä °ø°³µÇÁö ¾Ê¾ÒÁö¸¸, React & React-Dom ÀÇ ½ÃÇè ¹öÀüÀº ÀÌ¹Ì Meta ¿¡¼ °¡µ¿µÇ°í ÀÖÀ¸¸ç, ¿ì¸®µµ Áö±Ý ¹Ù·Î »ç¿ëÇغ¼ ¼ö ÀÖ½À´Ï´Ù.
ÂüÁ¶¹®¼:
https://react.dev/blog/2024/04/25/react-19-upgrade-guide
https://react.dev/learn/react-compiler
-
install React.19 RC
npm install react@rc react-dom@rc
Typescript ÀÇ Å¸ÀÔ Áö¿ø ¼³Á¤ :
// package.json ¿¡ ´ÙÀ½À» Ãß°¡
{
"dependencies": {
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
},
"overrides": {
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
}
}
-
Codebase ¶óÀ̺귯¸®ÀÇ È£È¯¼º °Ë»ç
# npx react-compiler-healthcheck@latest
// ÀÌ·± Ãß°¡ ÀνºÅçÀÌ ÇÊ¿äÇÏ´Ù´Â ÇÁ·ÒÇÁÆ®°¡ ³ª¿À¸é,
Need to install the following packages:
[email protected]
// 'y' ¸¦ ÃÄÁݽôÙ.
Successfully compiled 48 out of 56 components.
StrictMode usage not found.
Found no usage of incompatible libraries.
// incompatible libraries °¡ ¾ø´Ù¸é free to go
react »ýÅÂ°è ¸ðµç ¶óÀ̺귯¸®ÀÇ Á¤»óÀÛµ¿ÀÌ º¸ÀåµÇÁö ¾Ê½À´Ï´Ù.
-
EsLint
npm install eslint-plugin-react-compiler
// eslint config ¿¡ Ãß°¡
module.exports = {
plugins: [
'eslint-plugin-react-compiler',
],
rules: {
'react-compiler/react-compiler': "error",
},
}
-
¹øµé·¯ Æ¯È ¼³Á¤
-
-
Babel
npm install babel-plugin-react-compiler
// babel.config.js
const ReactCompilerConfig = { };
module.exports = function () {
return {
plugins: [
['babel-plugin-react-compiler', ReactCompilerConfig], // must run first!
// ...
],
};
};
b.
vite
// vite.config.js
const ReactCompilerConfig = { };
export default defineConfig(() => {
return {
plugins: [
react({
babel: {
plugins: [
["babel-plugin-react-compiler", ReactCompilerConfig],
],
},
}),
],
// ...
};
});
// Reactt.Compiler ÀÇ ¿É¼Ç ¼³Á¤
// µðÆúÆ® ¼³Á¤Àº ¸ðµç ÄÄÆ÷³ÍÆ®¿¡¼ ÄÄÆÄÀÏ·¯ true ÀÔ´Ï´Ù.
// annotation ¸ðµå¸¦ ¼³Á¤ÇØÁÖ¸é, °¢ ÄÄÆ÷³ÍÆ®¿¡¼ use memo ½ºÅ×ÀÌÆ®¸ÕÆ®¸¦ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
const ReactCompilerConfig = {
compilationMode: "annotation",
};
c.
Next.js
// Next.js canary, which uses React 19 Release Candidate
npm install next@canary babel-plugin-react-compiler
// next.config.js
const nextConfig = {
experimental: {
reactCompiler: true,
// ¶Ç´Â
// reactCompiler: "annotation"
},
};
module.exports = nextConfig;
d.
Remix
..´Â ¹®ÇåÀ» ÂüÁ¶
ÄÄÆ÷³ÍÆ®¿¡¼ React.Compiler »ç¿ë: