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
windowis for its attributes likeinnerwitdth, and adding raw browser events likeresizelocalStorageis to store JWT token