Skip to content

Instantly share code, notes, and snippets.

@kpdecker
Created April 14, 2016 01:44
Show Gist options
  • Save kpdecker/0b838284b7c7668aaae9d288f1d993a0 to your computer and use it in GitHub Desktop.
Save kpdecker/0b838284b7c7668aaae9d288f1d993a0 to your computer and use it in GitHub Desktop.
ClientOnly.jsx
/* 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
};
<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