When server-side rendering a React component that uses window
or localStorage
these browser global variables, I always need to add
if (typeof localStorage !== 'undefined') { // then do stuff }
to get rid of those 'localStorage is not defined' errors.
Is there any other decent solution to this?
Edit my use case
window
is for its attributes likeinnerwitdth
, and adding raw browser events likeresize
localStorage
is to store JWT token