Miss any of our Open RFC calls?Watch the recordings here! »

@react-corekit/use-where

1.1.2 • Public • Published

@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

Install

npm i @react-corekit/use-where

DownloadsWeekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

579 kB

Total Files

23

Last publish

Collaborators

  • avatar