/**
* @typedef
*/
type EnvironmentCheckReturn = {
/**
* Whether we are currently in Production mode
*/
prod: boolean
/**
* Whether we are currently in Development mode
*/
dev: boolean
}
/**
* Custom hook for providing the environment value for the current app context.
*
* The hook doesn't take any parameters and returns a set of booleans
* representing which environment state we are in.
*
* Currently only two environments are supported: `prod` and `dev`.
*
* The hook checks the value of `process.env.NODE_ENV` **during the build
* process** to determine what the current environment is. That means any
* application built by Jenkins will report as `prod`, even when hosted on
* `apps-test.jcu.edu.au`.
*
* That means that the main use of this hook is to detect if the app is
* running in the webpack dev server on a developer's machine (i.e. usually at
* `localhost:3000`).
*
*
* ### Hook Usage
*
* #### Checking the current environment
* ```
* const {dev, prod} = useEnvironmentCheck()
*
* ...
*
* if (dev) console.log("we are in dev mode")
* ```
*
* @category Hooks
* @return {EnvironmentCheckReturn}
*/
export function useEnvironmentCheck() : EnvironmentCheckReturn {
let prod = process.env?.NODE_ENV === 'production'
let dev = process.env?.NODE_ENV === 'development'
return {prod, dev}
}
Source