@straw-hat/is-ssr
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@straw-hat/is-ssr

Contains some functions that help you to identify if the execution of the code is happening in the server-side, or in the browser-side

Usage

  • References Please use yarn docs:reference to generate the reference docs.
import { isSSR, isBrowser, onSSR, onBrowser } from '@straw-hat/is-ssr';

if (isSSR()) {
  console.log('💻 I am running on the server-side.');
}

if (isBrowser()) {
  console.log('I am running on the browser-side.');
}

// Run the function on Server-Side

onSSR(function ssrCallback() {
  console.log('💻 I am running on the server-side.');
});

onSSR(
  function ssrCallback() {
    console.log('💻 I am running on the server-side.');
  },
  function browserCallback() {
    console.log('I am running on the browser-side.');
  }
);

// Run the function on Browser-Side

onBrowser(
  function browserCallback() {
    console.log('I am running on the browser-side.');
  },
  function ssrCallback() {
    console.log('💻 I am running on the server-side.');
  }
);

onBrowser(function browserCallback() {
  console.log('I am running on the browser-side.');
});

Package Sidebar

Install

npm i @straw-hat/is-ssr

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

4.11 kB

Total Files

5

Last publish

Collaborators

  • ubi