at Encraft #4 React/Next.js æåç· https://knowledgework.connpass.com/event/285601/
ã¯ãã ãã®ããã°ãããããèªãã§ããæ¹ãªãæ¢ã«ãåç¥ããããã¾ãããããã¹ããã³ããåç¥ã§ããããã ããããåæ£åãã¤ã¯ãããã°ã®ä¸ç¨®ã§ã2017å¹´ããã®Twitter社ã«ããæ¥æ¬äººã¤ã©ã¹ãã¬ã¼ã¿ã¼ã®å¤§è¦æ¨¡åçµãããã§ä¸ææ話é¡ã«ãªãã æè¿ã¾ãã¤ã¼ãã³ãã¹ã¯ã«ããTwitter社買åããå§ã¾ã£ãä¸é£ã®æ··ä¹±ã§å度å°ã話é¡ã«ããªãã¾ããã ã§ãã¾ãåã¨ãã¦ããã¹ããã³ã«å°æ¹é ãããããã§èªåã§éç¨ãã¦ãããã§ããããã¹ããã³ã®ã³ã¼ãã¯ä»ã¨ãªã£ã¦ã¯ã ãã¶å³ããã å³ããé¨åãæããã¨å²ã¨ããªããªããã§ããããã£ããæ¸ã㨠ããã³ãã¨ã³ããWebpackerã«ã¹ã£ããããã¤ç¬èªconfigãæ¸ãã¾ãã£ã¦ãã ããã©ã«ããé è½ããã¦ããWebpackerã¨åãããæçµçã«ã©ãããconfigã§webpackerãåãã¦ãã®ããã¶ã誰ãææ¡ã§ãã¦ãªã Typescriptãããªã åãã¦ãããã¨
Create React App(以ä¸ãCRAãã¨ãã)ã®å°æ¥ãããã³Reactã¨ãã¬ã¼ã ã¯ã¼ã¯ã®é¢ä¿æ§ã«ã¤ãã¦Danæ°ãGitHubã®Issueã®ã³ã¡ã³ãã§èªã£ãå 容ã®ç¿»è¨³ã§ããé常ã«é·ãã³ã¡ã³ãã§ãããReactã¦ã¼ã¶ã¼ã§ããã°ä¸èªã«å¤ããå 容ã ã¨æã£ãã®ã§ç¿»è¨³ãã¦ã¿ã¾ãããåèã«ãªãã°å¹¸ãã§ãã åæ 翻訳 ã¿ãªãããããã«ã¡ã¯ã CRAã®ç¾ç¶ã«ã¤ãã¦ã¯ä»¥åããçãã»ã©ããã£ã¦ãããããã«å¯¾å¦ããããã®ææ¡ã«åãçµãã§ããã¨ããã§ãããã®ãã«ãªã¯ã¨ã¹ãã¯è°è«ãå§ãããã¨ãç®çã«ãã¦ããã®ã§ãç§ãã¡ãCRAã®å°æ¥ã«ã¤ãã¦èãã¦ããããã¤ãã®èæ¯ã説æããè¯ãæ©ä¼ã ã¨æãã¾ããç§ãã¡ãèæ ®ãã¦ããçç±ã¨ãã¬ã¼ããªãã«ã¤ãã¦æ確ã«ãããã®ã§ãããã¤ãã®ã»ã¯ã·ã§ã³ãããªãé·ãã³ã¡ã³ãã«ãªãããã§ããããå ¨ã¦ãèªãæ°ã«ãªããªããªããæå¾ã®ã»ã¯ã·ã§ã³ã¾ã§ã¹ã¯ãã¼ã«ãã¦ç§ãã¡ãææ¡ããä»å¾ã®æ¹æ³ã
EventEmitter ã¨ãå¤é¨ã® UI ã©ã¤ãã©ãªè¾ºããå®çªãã¨æãï¼ã«ã«ã¼ã»ã«ãã¹ã©ã¤ãã¼ã®ã©ã¤ãã©ãªãèªåã§ã³ã³ãã¼ãã³ãã«ã©ããããçµé¨ã¯æ°ãããï¼ã æè¿ã® JS ã§ã¯ pure object + ç´ç²é¢æ°ã¨ãã #è¨è¨ ãåãã±ã¼ã¹ãå¢ãããããã¨ãã° DOM API ã«å¯¾ãã¦å¯ä½ç¨ãèµ·ãããã¥ã¼ã¿ãã«ãªå¦çã¯ã¯ã©ã¹ã§æ¸ããã»ããèªç¶ãªãã¨ãå¤ãï¼ã©ã¤ãã©ãªã new Slider ã®ãããªå½¢å¼ãåãã®ããããçç±ã ããï¼ã
ãWeb Speed Hackathon 2022ãã¨ãããé常ã«éããWebã¢ããªããã¥ã¼ãã³ã°ãã¦ãããã«é«éã«ãããã競ã競æããããã¾ãã ãªã¢ã¼ãåå ã§11æ1æ¥ãã27æ¥ã¾ã§éå¬ããã¦ãã¾ãã ããã§è¨ããé«éãã¨ã¯Core Web Vitalsã®ã¹ã³ã¢ãé«ããã¨ãè¨ããLighthouseã®ã¹ã³ã¢ããã¼ã¹ã«ãã500ç¹æºç¹ã®äºãã§ãã ISUCONã®ããã³ãã¨ã³ãçã§ããã 以åã«ãåã課é¡ã§ãå¦çåããã¨ã社å ï¼ãµã¤ãã¼ã¨ã¼ã¸ã§ã³ãï¼åãããè¡ãããããããã¾ã 500ç¹ãåºãã人ã¯ãã¾ããã ããã§åã¯ãæºç¹ãåºããããã¨æããåæ¥ãããããããããã©ã¤ã³ã°ãã¦ãããããã®åããé å¼µã£ã¦ãã¾ããã ããã¦ãå æ¥ï¼17æ¥ï¼ãã¤ãã«500ç¹æºç¹ãåºãã¾ããï¼ ãã¶ããã¬ã®ã¥ã¬ã¼ã·ã§ã³ã¯ã¯ãªã¢ãã¦ãããã¯ãã§ãï¼ããéåãã¦ããããã¾ããâ¦ï¼ã èªåã§è¡ããããVisual Re
Next.js ã®ããã¥ã¡ã³ãã«ã¯æ¬¡ã®ããã«è¨è¼ããã¦ã React will automatically cache fetch requests with the same input in a temporary cache. This is an optimization to avoid the same data being fetched more than once during a rendering pass - and is especially useful when multiple components need to fetch the same data. React ãèªåçã« fetch request ããã£ãã·ã¥ããã¨æ¸ãã¦ããã
Signals â Preact Guide 端çã«ãã£ã¦ãã¾ãã¨ãSolidã®ã½ã¬ã¨ã»ã¼åæ§ã®ä½é¨ã§ã³ã¼ããæ¸ããããã«ãªãã»ã»ã»ï¼ ã¾ãã¯ã³ã¼ã // store.js import { signal } from "@preact/signals"; export const count = signal(0); export const add = () => count.value++; // Counter.jsx import { count, add } from "./store.js"; const Counter = () => ( <div> <p>Count: {count.value}</p> <button onClick={add}>click me</button> </div> ); ãããã«ãã®æ代ã«ãªãã¨ããããæ¢è¦æããã£ã¦ããããªãèªããã³ã¼ãã
TypeScriptç°å¢ã§ã®Reactã® useRef ã¯ãåæå¤ã¨åå¼æ°ã®ä¸ãæ¹ã«ãã£ã¦è¿ãå¤ã®åã RefObject 㨠MutableRefObject ã®ã©ã¡ããã«ãªãã¾ããã©ããã使ãæ¹ã®ã¨ãã«ã©ãæ¸ãã¦ã©ã¡ããå¾ãã¹ãããã @types/react ã®æ´æ°ã¾ããã®è°è«ã追ã£ãçµæã示ãã¾ãã ãã®è¨äºã¯2021å¹´5æç¾å¨ãReact 17.0.2ãææ°ãã¼ã¸ã§ã³ã®æç¹ã§è¨è¿°ãã¾ãã åèã«ããæ å ± https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31065#issuecomment-446425911 RefObject 㨠MutableRefObject ãå¥ã§ããçç±ã«ã¤ã㦠https://github.com/DefinitelyTyped/DefinitelyTyped/pull/38228#i
TL;DR TanStack Query ã SWR ã®ãããªãã¼ã¿åå¾ã©ã¤ãã©ãªã¯ãé£ããã¨ããã Server State 管çãç°¡åã«ãã¾ããã¦ã¼ã¶ããªãã£ãã³ã³ãã¼ãã³ãè¨è¨ã®å質ãåä¸ããã¾ããå°å ¥ããéã«ã¯ããã¤ã注æããç¹ãããã¾ãã ï¼ããªãé·ããªã£ã¦ãã¾ã£ããããç®æ¬¡ãç®ã«çã¾ã£ãç®æã ãèªãã®ãè¯ããã¨æãã¾ãï¼ ã¹ã³ã¼ã ãã®è¨äºã¯ Client Side Rendering(CSR) ã® SPA ã対象ã¨ãã¾ããçè ï¼ã®æ¥åï¼ã®é¢å¿ãè¦æ±ãå°ãªããããSSR ã ISR ã¯ãã®è¨äºã®è°è«ã§ã¯å¯¾è±¡ã«ãã¾ãã[1]ãèªã¿è¾¼ã¿ããã©ã¼ãã³ã¹ã«ã¤ãã¦ãè¦æ±ã¯æ§ããã§ãã å©ç¹ãè°è«ã¯ç¹å®ã® UI ã©ã¤ãã©ãªã»ãã¬ã¼ã ã¯ã¼ã¯ã«éãã¾ããããçè ãæ £ãã¦ãã React ã使ã£ã¦èª¬æãã¾ãã äºåç¥è React ã® State ã«ã¤ã㦠ãã®è¨äºã§ã¯ãReact ã® Stat
ãã®è¨äºã¯Styled Componentsã®å¾®ç´°ãªå¥½ã¿ã«é¢ãããã®ã§ãããStyled Componentsã§æ§æãããããã¸ã§ã¯ãããªãã¡ã¯ã¿ãªã³ã°ãã¹ãçã®èãã¯ããã¾ããã Styled Componentsã¯CSS in JSã®å é§ãã¨ãªãããã®æã®ãã¼ã«ã§ã¯ãããã¯ã©ã¹ã®äººæ°ã§ããè¦ããããã¾ããã§ãããå®ã®ã¨ãããã¾ãæ¿«ç¨ããã¦æ¬²ãããªãæ°æã¡ãæ±ãã¦ãã¾ãã ç¹è¨äºé CSSãReactã®åå¦è åãã§ã¯ããã¾ããã ãã®è¨äºã¯ä»¥ä¸ã®æ¯éãåããã®ã§ã¯ããã¾ããã CSS in JS / Plain CSS CSSãã¡ã¤ã«ãåé¢ãã / åé¢ããªã ãã³ãã¬ã¼ããªãã©ã« / Object Style CSSã³ã¼ãã®ã¹ã¿ã¤ã« ã¯ããã« Styled Componentsã«ã¤ã㦠Styled Componentsã¨ããã©ã¤ãã©ãªã¯ãstyled.div...ã®ãããªAPIãæã¤
import type { ConfigFile } from "@rtk-query/codegen-openapi"; // https://redux-toolkit.js.org/rtk-query/usage/code-generation#simple-usage const config: ConfigFile = { schemaFile: "https://petstore3.swagger.io/api/v3/openapi.json", apiFile: "./store/emptyApi.ts", apiImport: "emptySplitApi", outputFile: "./store/petApi.ts", exportName: "petApi", hooks: true, }; export default config; import { empty
æ¬ç¨¿ã¯ãNext.js ã§ãgetServerSideProps ã API Routesããå©ç¨ããã¢ããªã±ã¼ã·ã§ã³åãå 容ã«ãªãã¾ããéåãªä½ãã«ãªãã®ã§ãè¦ä»¶ã«é©åããã»ããªãã¯ããã¨æãã¾ãã®ã§ããããããã Next.js ã¯èããã¬ã¼ã ã¯ã¼ã¯ Next.js 㯠SPA é ä¿¡ã®æé©åã«ãã©ã¼ã«ã¹ãã¦ãããBackend ã®æ©è½é¢ãååã¨ã¯è¨ãã¾ãããpages ã® Page ã³ã³ãã¼ãã³ãã API Routes ã¯ãcontroller ã¨ãã¦ã®æ©è½ãæä¾ããã®ã¿ã§ããããã¥ã¡ã³ããè¦ã¦ããããã¨ãããä¸é£å¦çã¯ããããã middleware ãã©ããã¼é¢æ°ãç¨æããã®ã常å¥æ段ãã¨æãã¾ãã NestJS ã«ãããã㪠Service 層ã欲ãã Node.js Backend ãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦ãNestJS ã¯æåãªåè£ãã¨æãã¾ããã¬ã¤ã¤ã¼ãã¢ã¸ã¥ã¼ã«ã»DI ã®æ§
Reactã¢ããªã±ã¼ã·ã§ã³ã®ãã¹ãæ¦ç¥ã«ã¤ã㦠ã»ããã³ãã¨ã³ãã®ãã¹ãã®ç¨®é¡ ã»ãã¬ã¼ããªã ã»æå±ãã¦ãããã¼ã / ãããã¯ãã®ç¶æ³ ã»ãã¹ãæ¦ç¥ ã»Storybookã使ã£ãããããã®ãã¹ãã¸
Reactãåãå·»ãç¶æ 管çã®æ½®æµãå¦ã¼ããHooksãServer Componentsãªã©ã®ç»å ´ã§ä½ãå¤ããã Reactãåãå·»ãç¶æ 管çã®ã¢ããã¼ãã¯å¤åãç¶ãã¦ãã¾ããããã¾ç¥ã£ã¦ããã¹ãææ³ã¨ã¯ã©ã®ãããªãã®ã§ãããããå°æ 徹ï¼@koba04ï¼ããã«ãç¾å¨ãããã¦ãã®å ã®ç¶æ 管çã«ã¤ãã¦å·çããã ãã¾ããã ããã«ã¡ã¯ãå°æï¼@koba04ï¼ã§ãã 2019å¹´5æã«ãSPAã«ãããç¶æ 管ç:é¢æ°åã®ã¢ããã¼ããåãå ¥ããããã³ãã¨ã³ãç³»ã¢ã¼ããã¯ãã£ã®å¤é·ãã¨ããè¨äºãæ¸ãã¾ãããããããã2年以ä¸ãçµéããReactãç¨ããç¶æ 管çã¯å¤§ããå¤ããã¾ãããæ¬è¨äºã§ã¯Reactãåãå·»ãç¶æ 管çã®å¤é·ã«ã¤ãã¦è§£èª¬ãã¾ãã åºããReduxã®æ¡ç¨ Hooksã®ç»å ´ ã³ã³ãã¼ãã³ãããªã¼ããç¬ç«ããç¶æ 管ç Concurrent Featuresã«ããæ°ããã¦ã¼ã¶ã¼ä½é¨ ç¶æ ã¨ãã£
Lighthouse ã® Performance ã¹ã³ã¢ã52ãã94ã«ä¸ããã Beforeã Afterã æ½çã¨ãã¦å ·ä½çã«ä½ãè¡ã£ãã®ããæ¸ãã¦ããã çµç·¯ 以åãShape Painter ã¨ãã SPA ãä½ã£ãã æ§æã¯ã·ã³ãã«ã§ãã¨ã³ããªãã¤ã³ãã¯ã²ã¨ã¤ã ããããã¦ããã§ãã©ã¤ãã©ãªã®ã³ã¼ãããã³ãã«ããvendors.contenthash.jsã¨ãã¢ããªã±ã¼ã·ã§ã³ã®ã³ã¼ãããã³ãã«ããindex.contenthash.jsãèªã¿è¾¼ãã§ããããµã¼ãã¨ã®éä¿¡ã¯ãã¼ã¸èªã¿è¾¼ã¿æã®ã¿ã§ããã¨ã¯ããã³ãã¨ã³ãã§å®çµãã¦åä½ããã React ã Redux ã®ç¿ä½ã¨ããæå³åããå¼·ããå ¬éå¾ã¯æ¾ã£ã¦ãããã®ã ãããªãã¨ãªã Tree ãã¼ã¸ã Lighthouse ã§ã¹ã³ã¢ãè¨æ¸¬ãã¦ã¿ãã¨ãããPerformance é ç®ãã¾ããã®52ã ã£ãã ããã©ã¼ãã³ã¹ãæèããã«ä½ã£ã¦
ããã«ã¡ã¯ãã¯ã¬ã¹ã¦ã§ã¢æ ªå¼ä¼ç¤¾ã®å¥¥é賢太é ( @okunokentaro ) ã§ããä»å¹´ããããããé¡ããã¾ãã ä»åã¯ãReactã§ã®ã¯ãªã¼ã³ã¢ã¼ããã¯ãã£ã®æ¡ç¨ã®æ¯éã«ã¤ãã¦Twitterã«ã¤ã¶ãããã¨ãããæãã®å¤Likeãéã¾ã£ããããã¾ã¨ãã¦é²è¦§ã§ããããã«ãã¤ã¼ããã¾ã¨ãã¤ã¤ãç°¡åã«è£è¶³ããããã¨æãã¾ãã ãªã¢ã¯ã·ã§ã³ã®ãã¨ã¨ãªã£ãè¨äº Webããã³ãã¨ã³ãã®éçºå¹çãé«ãä¿ã¤ããã®èãæ¹ @adwdããã®ãã®è¨äºã«æéãåãã¦ãTwitterã§ã¡ãã»ãææ³ãã¤ã¶ãããã¨ããLikeãRTãäºæ³å¤ã«éã¾ãã¾ããããããä¸è¨ã®ãã¤ã¼ãã§ãã çè ããã¤ã¼ããããã® è£è¶³ çè ã¯ãå è¨äºã§è¨åããã¦ããããæªãæ¹ãè¯ããååã¨åã®ä½é¨è«ããã質ã¨ã¹ãã¼ãï¼2020ç§100åæ¡å¤§çï¼ãã¯ç¢ºèªæ¸ã¿ã§ãããã Clean Architecture é人ã«å¦ã¶ã½ããã¦ã§ã¢ã®æ§é ã¨è¨è¨
çããããã«ã¡ã¯ãçè ã®ä»¥åã®è¨äºã§ã¯ãReactã®useMemoãç¡é§ã«ä½¿ããã¨ã«ããã¬ã³ããªã³ã°é度ã®ãªã¼ãã¼ããããã©ãããããããã³ããã¼ã¯ã«ãã£ã¦ç¤ºãã¾ããã ããã«ããã°ãã¹ãã¼ããã©ã³ãæ³å®ããã¨ãã¦ããuseMemoã ãã§æç»ã«ç®ã«è¦ããå½±é¿ãä¸ããï¼16msãããã®é 延ãçºçãããï¼ã«ã¯ä¸ã®ãªã¼ãã¼ã®useMemoãå¿ è¦ãªãã¨ãåããã¾ãã é度ã§ã¯ãªãuseMemoã使ããã¨ã«ããã¡ã¢ãªæ¶è²»éã®å¢å ãæ°ã«ãã声ãèããã¾ãããããã¿ã¾ãããçè ã¯ããã¾ã§ã¡ã¢ãªã¯ãªãã£ã«ã«ãªã¢ããªãReactã§æ¸ãããã¨ããªãç¥è¦ã«ä¹ãããããä»åã¯ãã®è¨äºã®å¯¾è±¡å¤ã¨ãªãã¾ãã ãã®çµæãåºããã¨ã§useMemoããã¤ä½¿ãã®ããªã©ã¨ããè°è«ã«ã¯çµæ¢ç¬¦ãæããããã¨æããããä¸è¨ã®è¨äºã®ææ³ãªã©ãè¦ã¦ããã¨ã¾ã å§ã åã ã§ãã ããã§ããã®è¨äºã§ã¯çè ã®èããçããã«å ±æãããããããã£ã¦ã
Reactã¢ããªã±ã¼ã·ã§ã³ã®ã¢ã¼ããã¯ãã£ã®ä¸ä¾ã¨ãã¦å ¬éããã¦ããGitHubãªãã¸ããªãbulletproof-reactãã大å¤åå¼·ã«ãªãã®ã§ãç§èªèº«ã®è¦è§£ã交ãã¤ã¤ã·ã§ã¢ãã¾ãã â»2022å¹´11æè¿½è¨ è¨äºãªãªã¼ã¹ãã1å¹´ã»ã©çµéãã¦ãæ°ããåºã¦ããæ å ±ãèãæ¹ãçãè¾¼ãã ç¶ç·¨è¨äºãæ¸ãã¦ããã ãã¦ããã®ã§ããã¡ããä½µãã¦èªãã§ããã ããã°ã¨æ³ãã¾ãï¼@t_keshiãããããã¨ããããã¾ãï¼ï¼ã ãã£ã¬ã¯ããªæ§é ãåå¼·ã«ãªã ã¾ãã¯ããã¸ã§ã¯ããã¨ã«ãã©ã¤ããã¡ãªãã£ã¬ã¯ããªæ§é ã«ã¤ãã¦ã ã½ã¼ã¹ã³ã¼ãã¯src以ä¸ã«å ¥ãã bulletproof-reactã§ã¯ãReactã«é¢ããã½ã¼ã¹ã³ã¼ãã¯srcãã£ã¬ã¯ããªä»¥ä¸ã«æ ¼ç´ããã¦ãã¾ããéã«è¨ãã°ãã«ã¼ããã£ã¬ã¯ããªã«componentsãutilsã¨ãã£ããã£ã¬ã¯ããªã¯ããã¾ããã ãã¨ãã°Create Next Appã§ä½æ
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}