# React Hooks & API

We provide a set of custom hooks to interact with the phone's core functions.

### useNuiEvent

Listens for events sent from the Lua client script.

{% code title="LUA CLIENT" overflow="wrap" lineNumbers="true" %}

```lua
Core.SendNuiMessage("MyCustomEvent", { someData = "Hello" })
```

{% endcode %}

{% code title="REACT" %}

```typescript
import { useNuiEvent } from '@/hooks/useNui';

const MyComponent = () => {
    useNuiEvent<{ someData: string }>('MyCustomEvent', (payload) => {
        console.log(payload.someData); // "Hello"
    });
}
```

{% endcode %}

### useNuiCallback

Triggers a client-side NUI Callback and awaits a response.

{% code title="LUA CLIENT" overflow="wrap" lineNumbers="true" %}

```lua
RegisterNUICallback("Core:MyCallback", function(data, cb)
    print("Received:", data)
    cb({ success = true })
end)
```

{% endcode %}

{% code title="REACT" overflow="wrap" lineNumbers="true" %}

```typescript
import { useNuiCallback } from '@/hooks/useNui';

const MyComponent = () => {
    const [triggerCallback] = useNuiCallback<string, { success: boolean }>('Core:MyCallback');
    
    useEffect(() => {
        triggerCallback("Data sent to client").then((response) => {
            if (response.success) {
                console.log("Callback successful");
            }
        });
    }, [triggerCallback]);
}
```

{% endcode %}

### useSettings

Retrieves the current player settings (wallpaper, scale, zoom, etc.). You can check the settings structure at `web\src\types\types.ts`

{% code title="REACT" overflow="wrap" lineNumbers="true" %}

```typescript
const MyComponent = () => {
    const settings = useSettings();
    // Access settings properties here
}
```

{% endcode %}

### useLanguage

Handles localization based on the user's selected language.

{% code title="REACT" overflow="wrap" lineNumbers="true" %}

```typescript
import { useLanguage } from '@/hooks/useLanguage';

const MyComponent = () => {
    const language = useLanguage();
    
    return <span>{language.getLang("MyTranslationKey")}</span>;
}
```

{% endcode %}

### useNavigateWithApps

A wrapper around the router to ensure smooth transitions between apps.

{% code title="REACT" overflow="wrap" lineNumbers="true" %}

```typescript
import { useNavigateWithApps } from '@/hooks/useNavigateWithApps';

const MyComponent = () => {
    const navigate = useNavigateWithApps();
    
    const handleClick = () => {
        navigate('/internal-route');
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.17movement.net/phone/building-custom-apps/react-hooks-and-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
