1.1.2 • Published 4 years ago
@react-corekit/use-where v1.1.2
@react-corekit/use-where
React Hook that detects if the javascript is being loaded from a server (SSR) or a web client
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
React's ReactDomServer object Reference
License
MIT © glongh