e t l e t l fi h fi h fi h e e e t r t r t r ォリヺ作りたいな〜 どうやってシヺハヺを回ろう… 野菜に⾁にォリヺラヺに調味料… e t l e t l e t l fi h fi h fi h e e e t r t r t r キセめんどくね!?! ォリヺのための陳列にしたら助かるよね o t o t o t a o a o a o n n n e e e u y u y o o u y o t r t r t r
a a a a B t s a B t s a B t s b t > b t > b t > b t > b t > b t > o o o l o l y s y s o o o l o l t e t e o o l y s o o l t e 仕様を満たすためにPropsが雪だるま式に増えていく type PageButtonsProps = { hogeButtonSubmit: boolean; fugaButtonSubmit: boolean; handleHogeButtonSubmit: boolean; handleFugaButtonSubmit: boolean; ...(disabled, state, ...) } あれ?これ俺普段からやってたわ Ž キセヅォLPとかでも意識できるか考えよう! いつの間にかキセヅォ依存ヨリヺになってしまう! Compositionで薄くする a a a a B t s a B t s a B t s b t > b t > b t > b t > b t > b t > i l i l i l <PageButtons hogeButton={( <button type="button" onClick={handleHogeButtonSubmit}> textA </button> )} fugaButton={( <button type="button" onClick={handleOK}> OK </button> )} /> children PropsでももちろんOK <PageButtons> <button type="button" onClick={handleHogeButtonSubmit}> textA </button> <button type="button" onClick={handleOK}> OK </button> </PageButtons>
o e e o e e o e e o l n o l n o l n o e e o e e o e e o e e o e e o e e o l n o l n o l n o <ClientComponent> <ServerComponent /> // <- OK. </ClientComponent> こういう別ディレクティブのものをChildrenにすることを"donut" patternっていうらしい 例えば - ブログ p p p a e a e e e a e e h e h e r r h e r 弱点 Compositionだとprops渡せないよね そういうどうしてもな時にuseContextを使おう p p p o e o e o e r i r r i r r i r o P v e o P v e o P v e o I m o I m o I m o o t n o o t n i i o e o e o o t n i o e "use cache" 実は"use cache"ディレクティブでも同じことができる export default async function Page() { const uncachedData = await getData() return ( <CacheComponent> <DynamicComponent data={uncachedData} /> </CacheComponent> ) } async function CacheComponent({ children }: { children: ReactNode }) { 'use cache' const cachedData = await fetch('/api/cached-data') return ( <div> <PrerenderedComponent data={cachedData} /> {children} </div> ) } a a a a e m a e m a e m y m C p y m C p y m C p r e e d m r e e d m r e e d m t i t i e e n e e n t i e e n P P o e o e P o e S S H e H e S H e