Last active
July 24, 2018 21:37
-
-
Save srph/ed6a2dcff19b5dabadc1c7d367cc56b9 to your computer and use it in GitHub Desktop.
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
function Header() { | |
return null | |
} | |
function Body() { | |
return null | |
} | |
function Footer() { | |
return null | |
} | |
class BaseLayout extends React.Component { | |
static Header = Header | |
static Body = Body | |
static Footer = Footer | |
render() { | |
const {children} = this.props | |
const header = children.find(child => child.type === Header) | |
const body = children.find(child => child.type === Body) | |
const footer = children.find(child => child.type === Footer) | |
return ( | |
<div class="container"> | |
<header> | |
{header ? header.props.children : null} | |
</header> | |
<main> | |
{body ? body.props.children : null} | |
</main> | |
<footer> | |
{footer ? footer.props.children : null} | |
</footer> | |
</div> | |
) | |
} | |
} | |
export default BaseLayout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment