isProduction

Overview

This utility is designed to help determine whether the application is running in production mode (e.g., a game environment) or development mode (e.g., a browser environment). It provides a simple function that serves as an alternative to repeatedly checking process.env.NODE_ENV === 'production'.

By using this utility, developers can streamline their code and avoid redundant checks, ensuring a cleaner and more maintainable codebase. It is especially useful in distinguishing between different execution environments for various configurations or logging purposes.

Usage

Importing the Utility

import { isProduction } from "@yankes/fivem-react/utils";

Example

In Game

import { useState } from "react"; 
import { isProduction } from "@yankes/fivem-react/utils";

export const MyComponent = () => {
    const [playerName, setPlayerName] = useState<string | null>("john.doe");

    return (
        <div>
            {isProduction() && playerName ? `Hi, ${playerName}!` : "You can see this content only in in game!"} // Hi, john.doe!        
        </div>
    )
}

In Browser

import { useState } from "react"; 
import { isProduction } from "@yankes/fivem-react/utils";

export const MyComponent = () => {
    const [playerName, setPlayerName] = useState<string | null>("john.doe");

    return (
        <div>
            {isProduction() && playerName ? `Hi, ${playerName}!` : "You can see this content only in in game!"} // You can see this content only in in game!        
        </div>
    )
}

Last updated