Last active
July 17, 2017 15:02
-
-
Save tybro0103/6c0da722300a273463ea39f65746bc94 to your computer and use it in GitHub Desktop.
Simple Isomorphic Bits
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
const isoComps = { | |
'session-menu-root': SessionMenu, | |
}; | |
const isoData = window.isoData || {}; | |
Object.keys(isoData).forEach(id => { | |
const props = isoData[id]; | |
const el = document.getElementById(id); | |
const Comp = isoComps[id]; | |
if (props && el && Comp) { | |
render(<Comp {...props} />, el); | |
} | |
}); |
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
class MainLayout extends Component { | |
getIsoData() { | |
return { | |
'session-menu-root': { | |
currentUser: this.props.currentUser, | |
}, | |
}; | |
} | |
renderIsoComp(id, Component) { | |
const data = this.getIsoData()[id]; | |
return <div id={id}><Component {...data} /></div>; | |
} | |
render() { | |
const isoData = this.getIsoData(); | |
const isoDataJs = `window.isoData = ${JSON.stringify(isoData)};`; | |
return ( | |
<Html> | |
<div className="header">{/*...*/}</div> | |
<div className="main"> | |
<Whatevs /> | |
{this.renderIsoComp('session-menu-root', SessionMenu)} | |
</div> | |
<div className="footer">{/*...*/}</div> | |
<script dangerouslySetInnerHTML={{ __html: isoDataJs }} /> | |
</Html> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment