Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Last active November 20, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/c5674811bcbd76997755bdcd7df50306 to your computer and use it in GitHub Desktop.
Save kwhinnery/c5674811bcbd76997755bdcd7df50306 to your computer and use it in GitHub Desktop.
SSR pattern
import React from 'react';
const SSR = typeof window === 'undefined';
function _ClientOnly() {
return(
<div style={{
backgroundColor: localStorage.getItem('backgroundColor')
}}/>
);
}
export default function ClientOnly(props) {
if (SSR) {
return <div/>;
} else {
return <_ClientOnly {...props} />;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment