JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 54363
  • Score
    100M100P100Q152709F
  • License MIT

☯️ React hook to determine if you're on the server or browser

Package Exports

  • use-ssr

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-ssr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

useSSR

☯️ React hook to determine if you're on the server or browser

undefined undefined

Need to know when you're on the server or in the browser in your components? This simple hook makes it easy. 🔥

Features

  • SSR (server side rendering) support
  • TypeScript support
  • Zero dependencies

Examples

Installation

yarn add use-ssr      or     npm i -S use-ssr

Usage

const App = () => {
  const { isBrowser, isServer } = useSSR()
  /*
   * In your browser's chrome devtools console you should see
   * > IS BROWSER: 👍
   * > IS SERVER: 👎
   *
   * AND, in your terminal where your server is running you should see
   * > IS BROWSER: 👎
   * > IS SERVER: 👍
   */
  console.log('IS BROWSER: ', isBrowser ? '👍' : '👎')
  console.log('IS SERVER: ', isServer ? '👍' : '👎')
  return (
    <>
      Is in browser? {isBrowser ? '👍' : '👎'}
      <br />
      Is on server? {isServer ? '👍' : '👎'}
    </>
  )
}

Options

const {
  isBrowser,
  isServer,
  canUseWorkers,
  canUseEventListeners,
  canUseViewport,
} = useSSR()

Todos

  • codesandbox examples
  • tests
  • badges