Docs
useEnvCheck

Check the environment (development, production, test) in which the application is running with the useEnvCheck hook, allowing for environment-specific logic.

Installation

pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-env-check

Usage

"use client"
 
import { useEnvCheck } from "@/hooks/use-env-check"
 
export function Component() {
  const { isBrowser, isDev, isProd, isEnv } = useEnvCheck()
 
  if (isEnv("dev")) {
    console.log("Running in development mode")
  }
 
  return (
    <div>
      {isBrowser && <p>Rendered in browser</p>}
      {isProd && <p>Optimized for production</p>}
    </div>
  )
}

API Reference

Return Values

NameTypeDescription
isBrowserbooleanIndicates if the code is running in a browser environment.
isServerbooleanIndicates if the code is running in a server environment.
isTestbooleanIndicates if the code is running in a test environment.
isDevbooleanIndicates if the code is running in a development environment.
isProdbooleanIndicates if the code is running in a production environment.
isEnv(env: "browser" | "server" | "dev" | "prod" | "test") => booleanFunction to check if the current environment matches the specified one.