Created
December 24, 2020 00:35
-
-
Save kwoncharles/7b8ee145d09af5e9076e18f5fb6860ec to your computer and use it in GitHub Desktop.
You might need render props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Page() { | |
return ( | |
<Layout> | |
{/* Tab의 상태는 WithTab 내부로 추상화 */} | |
<WithTab items={tabItems}> | |
{selectedTab => { | |
switch (selectedTab) { | |
case 'LOGIN': | |
return <Login /> | |
case 'JOIN': | |
return <Join /> | |
case 'HOME': | |
default: | |
return <Home /> | |
} | |
}} | |
</WithTab> | |
</Layout> | |
) | |
} | |
// 꼭 children으로만 함수를 전달할 필요는 없습니다 :) | |
function Page() { | |
return ( | |
<Layout> | |
<WithTab | |
items={tabItems} | |
renderContent={selectedTab => { | |
switch (selectedTab) { | |
case 'LOGIN': | |
return <Login /> | |
case 'JOIN': | |
return <Join /> | |
case 'HOME': | |
default: | |
return <Home /> | |
} | |
}} | |
/> | |
</Layout> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment