Skip to content

Instantly share code, notes, and snippets.

@davidfurlong
Last active March 16, 2017 14:25
Show Gist options
  • Save davidfurlong/90724955096ece4631d6ace3f0e1d174 to your computer and use it in GitHub Desktop.
Save davidfurlong/90724955096ece4631d6ace3f0e1d174 to your computer and use it in GitHub Desktop.
disable server side rendering for a react component [hacky]
/*
A react higher order component (HOC) for disabling server side rendering (SSR) for a particular component.
Useful if a particular library / page doesn't support SSR and you
a) dont want to mess around with the server routing to handle it
b) dont want to the component to even be constructed on the server
c) dont want to modify the component's methods to handle loading the library on the client
(for example, you need to use window/client methods in the constructor)
DISCLAIMER: this is hacky, and will throw a console warning (in development) that the checksum is invalid (which means server & client rendering dont agree on HTML string)
It will also discard the server side rendering for this route
*/
const disableSSR = WrappedComponent => props => __CLIENT__ ? (<WrappedComponent {...props}/>) : null
export default disableSSR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment