Skip to content

Instantly share code, notes, and snippets.

@Andy-set-studio
Created December 18, 2019 16:04
Show Gist options
  • Save Andy-set-studio/61e5f92eaf4a6b3a1663daee8984ba7f to your computer and use it in GitHub Desktop.
Save Andy-set-studio/61e5f92eaf4a6b3a1663daee8984ba7f to your computer and use it in GitHub Desktop.
Detect wether this is a browser context or not
// Returns true if we’re in a browser
const isBrowser = () => {
return typeof window !== 'undefined';
};
@Andy-set-studio
Copy link
Author

Example usage:

import isBrowser from './path/to/is-browser';

export default () => {
  if(!isBrowser()) {
    return null;
  }

  return (
    <button>Hi pal</button>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment