Created
April 14, 2016 01:44
-
-
Save kpdecker/0b838284b7c7668aaae9d288f1d993a0 to your computer and use it in GitHub Desktop.
ClientOnly.jsx
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
/* eslint-disable react/prop-types, react/no-did-mount-set-state */ | |
import React from 'react'; | |
let initialRender = true; | |
export default class ClientOnly extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {initialRender}; | |
} | |
componentDidMount() { | |
if (this.state.initialRender) { | |
initialRender = false; | |
this.setState({initialRender}); | |
} | |
} | |
render() { | |
return !this.state.initialRender ? this.props.children : <div />; | |
} | |
} | |
ClientOnly.propTypes = { | |
children: React.PropTypes.element | |
}; |
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
<ClientOnly> | |
<div style={{flex: 1}}> | |
<a | |
href="#" | |
className={`btn btn-transparent pull-right ${css.loginButton}`} | |
{... onActivate(() => this.props.onSignIn())} | |
> | |
Log In or Register | |
</a> | |
</div> | |
</ClientOnly> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment