Overview:
The content is providing an introduction to a boilerplate for getting started with React in NUI. It is designed for both browser and in-game based development workflows and includes utilities and examples to work off of.
Features:
Lua Utils:
- SendReactMessage: A wrapper for dispatching NUI messages, designed to be used with the useNuiEvent React hook.
- debugPrint: A debug printing utility dependent on a convar, which prints out to the console if the convar is set.
React Utils:
- useNuiEvent: A custom React hook for intercepting and handling messages dispatched by game scripts.
- fetchNui: A NUI focused wrapper around the standard fetch API, used for active NUI data fetching or triggering NUI callbacks in game scripts.
- debugData: A function allowing for mocking dispatched game script actions in a browser environment, triggering useNuiEvent handlers as if they were dispatched by the game scripts.
Misc Utils:
- isEnvBrowser(): Returns a boolean indicating if the current environment is a regular browser, useful for logic in development.
Installation:
To install the boilerplate, follow these steps:
- Clone the repository or use the template option and place it within your resources folder.
- Navigate to the web folder within a terminal of your choice.
- Type
npm ioryarnto install the dependencies.
Summary:
This article introduces a boilerplate for React in NUI, providing utilities and examples to aid in browser and in-game based development workflows. It includes features such as Lua utilities, React utilities, and miscellaneous utilities, and provides instructions for installation.