@react-corekit/use-where

Detects if the javascript is being loaded from a server (SSR) or a web client

Usage no npm install needed!

<script type="module">
  import reactCorekitUseWhere from 'https://cdn.skypack.dev/@react-corekit/use-where';
</script>

README

@react-corekit/use-where

React Hook that detects if the javascript is being loaded from a server (SSR) or a web client

NPM JavaScript Style Guide

Install

npm install --save @react-corekit/use-where
yarn add @react-corekit/use-where

Syntax

const [isBrowser, isNode, isServer] = useWhere();

Returns

isBrowser

A function that detects if the code is being executed in a web browser.

isServer

A function that detects if the code is being executed in a server (SSR - Server side rendering).

isNode

A function that detects if the code is being executed in node environment (SSR - Server side rendering).

Usage

Visit: https://react-corekit.github.io/use-where/ for a minimalistic live demo

import React from "react";

import { useWhere } from "@react-corekit/use-where";

const App = () => {
  const [isBrowser, isNode, isServer] = useWhere();
  return (
    <div>
      <div>
        Is browser? <strong>{isBrowser() ? "Yes" : "No"}</strong>
      </div>
      <div>
        Is node? <strong>{isNode() ? "Yes" : "No"}</strong>
      </div>
      <div>
        Is server? <strong>{isServer() ? "Yes" : "No"}</strong>
      </div>
    </div>
  );
};
export default App;

Additional documentation

Node's Globals Documentation

Window Object Reference

React's ReactDomServer object Reference

License

MIT © glongh