Last active
May 31, 2018 19:02
-
-
Save renatorib/bb64cff9f1fcefcd5636dc3326d3629c to your computer and use it in GitHub Desktop.
SSR - Render Only In Client
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 OnlyInClient extends Component { | |
static defaultProps = { fallback: null } | |
state = { client: false } | |
componentDidMount() { | |
this.setState({ client: true }) | |
} | |
render() { | |
if (!this.state.client) { | |
return this.props.fallback | |
} | |
return this.props.children() | |
} | |
} | |
// nullable | |
<OnlyInClient> | |
{() => <Content />} | |
</OnlyInClient> | |
// with a fallback | |
<OnlyInClient fallback={<Spinner />}> | |
{() => <Content />} | |
</OnlyInClient> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment