Skip to content

Instantly share code, notes, and snippets.

@srph
Last active July 24, 2018 21:37
Show Gist options
  • Save srph/ed6a2dcff19b5dabadc1c7d367cc56b9 to your computer and use it in GitHub Desktop.
Save srph/ed6a2dcff19b5dabadc1c7d367cc56b9 to your computer and use it in GitHub Desktop.
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