useVisible
Overview
The useVisible
hook manages the visibility state of a UI component in a FiveM NUI environment. It listens for visibility updates via an NUI message and allows closing the UI programmatically.
Usage
Importing the Hook
Parameters
elementId
string
N/A
A unique identifier for the UI component.
initialValue
boolean | "DISPLAY_ON_DEVELOPMENT"
true
Determines the initial visibility state.
Return Value
The hook returns an object containing:
visible
boolean
Indicates if the UI component is visible.
close
function
A function to close the UI component.
isClosing
boolean
Indicates if the closing action is in progress.
Example
ReactJS
LUA
Notes
If
initialValue
is set to"DISPLAY_ON_DEVELOPMENT"
, the UI will only be visible in a development environment.Ensure proper communication between Lua and React NUI by using
SendNUIMessage
in Lua anduseNuiMessage
in React.
Conclusion
The useVisible
hook simplifies managing the visibility of NUI components in FiveM projects. It provides an efficient way to control UI state and seamlessly integrates with NUI messages.
Last updated