Created
September 22, 2021 10:21
-
-
Save 6220119/500f559abf1eb5605a08c7c185e8826e to your computer and use it in GitHub Desktop.
sample render-props vs react-teleporter
This file contains hidden or 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
import { createTeleporter } from "react-teleporter"; | |
const HeaderTitleSlot = createTeleporter(); | |
const HeaderActionsSlot = createTeleporter(); | |
const AppLayout = ({ children: content }) => { | |
return ( | |
<> | |
<Sidebar /> | |
<Header> | |
<HeaderTitleSlot.Target /> | |
<HeaderActionsSlot.Target /> | |
</Header> | |
{content} | |
</> | |
); | |
}; | |
export const HeaderTitle = HeaderTitleSlot.Source; | |
export const HeaderActions = HeaderActionsSlot.Source; | |
const DashboardPage = () => { | |
return ( | |
<AppLayout> | |
<HeaderTitle>Dashboard</HeaderTitle> | |
Dashboard Content goes here! | |
</AppLayout> | |
); | |
}; | |
const DetailsPage = () => { | |
return ( | |
<AppLayout> | |
<HeaderTitle><GoBack /> Details</HeaderTitle> | |
<HeaderActions> | |
<Add /> | |
<Edit /> | |
<Delete /> | |
</HeaderActions> | |
DetailsPage Content goes here! | |
</AppLayout> | |
); | |
}; |
This file contains hidden or 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
const AppLayout = ({ | |
title: headerTitle, | |
action: headerActions, | |
children: content, | |
}) => { | |
return ( | |
<> | |
<Sidebar /> | |
<Header title={headerTitle} actions={headerActions} /> | |
{content} | |
</> | |
); | |
}; | |
const DashboardPage = () => { | |
return <AppLayout title="Dashboard">Dashboard Content goes here!</AppLayout>; | |
}; | |
const DetailsPage = () => { | |
return ( | |
<AppLayout | |
title={ | |
<> | |
<GoBack /> Details | |
</> | |
} | |
actions={ | |
<> | |
<Add /> | |
<Edit /> | |
<Delete /> | |
</> | |
} | |
> | |
DetailsPage Content goes here! | |
</AppLayout> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment