Last active
November 20, 2021 16:00
-
-
Save kwhinnery/c5674811bcbd76997755bdcd7df50306 to your computer and use it in GitHub Desktop.
SSR pattern
This file contains hidden or 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
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