Hooks & Utilities
Hooks and utilities exported by dirk-cfx-react
Hooks
useNuiEvent
Listens for NUI messages from Lua client scripts. Manages event listener lifecycle automatically.
import { useNuiEvent } from "dirk-cfx-react";
useNuiEvent<{ visibility: boolean }>("SET_VISIBLE", (data) => {
setVisible(data.visibility);
});action
string
The NUI event name to listen for
handler
(data: T) => void
Callback fired when the event is received
The handler ref is updated on every render so you always have access to the latest closure values without re-registering the event listener.
useAudio
Zustand store for playing audio files via NUI.
import { useAudio } from "dirk-cfx-react";
const { play, stop } = useAudio();
play("click.ogg");useTornEdges
Generates torn/ripped edge clip paths for paper-style UI elements.
Utilities
fetchNui
Sends a POST request to the Lua client via FiveM's NUI callback system.
eventName
string
NUI callback name registered in Lua
data
unknown
Payload to send
mockData
T
Return this when running in a browser (dev mode)
When running in a browser environment (outside FiveM), fetchNui returns mockData if provided, or an empty object with a console warning.
locale
Locale string resolver. Fetches translations from the server via GET_LOCALES and supports %s placeholder substitution.
key
string
Locale key
...args
string[]
Values to substitute for %s placeholders
Locale strings are loaded from your resource's locales/en.json (or whichever language is configured).
useSettings
Zustand store holding server-provided settings. Populated automatically by DirkProvider.
game
"fivem" | "rdr3"
Current game
currency
string
Currency symbol (e.g. "$")
primaryColor
string
Mantine colour name
primaryShade
number
Shade index (0–9)
itemImgPath
string
Base URL for item images
resourceVersion
string
Current resource version
customTheme
MantineColorsTuple
Custom colour palette
useItems
Zustand store for inventory item definitions. Populated by the GET_ITEMS NUI callback.
colorWithAlpha
Helper to add alpha transparency to CSS colour strings.
createSkill
Factory for creating RuneScape-style XP/level curves.
inputMapper
Constants for FiveM input mapper categories and key names. Used internally by FiveMKeyBindInput.
Last updated