-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent SSR for Component #292
Comments
I haven't tested this myself, but what about trying to triggering a state in the Lifecycle constructor(props) {
super(props);
this.state = { shouldRenderComponent: false };
}
componentDidMount() {
this.setState({ shouldRenderComponent: true });
}
render() {
return (<div>{ this.state.shouldRenderComponent && <Component> }</div>);
} or Just check in render render() {
const shouldRender = typeof window !== 'undefined'; //
return (<div>{ shoulderRender && <Component }</div>);
} or Wrap it in a HOC const onlyRenderInBrowser = ComposedComponent => class extends React.Component {
render() {
const shouldRender = some browser check;
if (shouldRender) return <ComposedComponent {...this.props} />;
return null;
}
}
... Your component then remains pure
export default onlyRenderInBrowser(SomeComponent); (I haven't tried any of the above, but that's how I would go about solving it). Hopefully that helps. |
Here's what I'm using right now:
Key problem is that the checksum fails since the server side is empty where the client side has the leaflet map. Ideally the markup generated by the server is reused, we need to do it anyway for SEO, but not every client side component has to be included, e.g. a graph or input. |
Here's the warning I routinely get:
|
@nym @choonkending's example should resolve your error - since content will be the same on client and server, and the component will update only on client. For your example:
So server renders original markup without MapView |
We're cleaning up issues on the project and since this is an old issue we're closing it. |
I haven't been using it recently, so fine with me. |
I have a problem almost identical to erikras/react-redux-universal-hot-example#507
Is there a way to disable server side rendering for a specific component, or add it only when the renderer is in the browser?
The text was updated successfully, but these errors were encountered: