> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Use user actions

> Low-level actions for managing authenticated user state

## Overview

`useUserActions` is a low-level hook that provides direct access to the Redux actions and API mutations for the current user. In most cases you should use [`useUser`](https://docs.sublay.io/v7/hooks/user/use-user) instead, which wraps `useUserActions` and provides a higher-level interface.

Use `useUserActions` directly when you need to manually set or clear user state — for example, in a custom authentication flow.

## Usage Example

```tsx theme={null}
import { useUserActions } from "@sublay/react-js";

function CustomAuth() {
  const { setUser, clearUser } = useUserActions();

  const handleExternalLogin = async (token: string) => {
    const userData = await myAuthService.login(token);
    setUser(userData); // Sync the authenticated user into Sublay state
  };

  const handleLogout = () => {
    clearUser();
  };

  return (
    <>
      <button onClick={() => handleExternalLogin("token")}>Login</button>
      <button onClick={handleLogout}>Logout</button>
    </>
  );
}
```

## Return Values

**setUser** `(user: AuthUser | null) =\> void`

Manually sets the current user in Redux state. Validates that the user object has an `id` before setting — partial or empty objects are silently ignored.

**clearUser** `() =\> void`

Clears the current user from Redux state and resets any error.

**updateUser** `(params: \{ projectId: string; userId: string; update: UpdateUserParams; currentUser?: AuthUser \}) =\> Promise\<AuthUser\>`

Calls the update user API and manages loading and error state. Applies optimistic updates for non-file fields. Reverts to `currentUser` if the request fails.

**params**

**projectId** `string` *required*

The project ID.

**userId** `string` *required*

The authenticated user's ID.

**update** `UpdateUserParams` *required*

Fields to update. See [`useUser`](https://docs.sublay.io/v7/hooks/user/use-user) for the full `UpdateUserParams` reference.

**currentUser** `AuthUser`

The current user snapshot used to revert state on failure.

**clearError** `() =\> void`

Clears any error stored in the user slice.

> [!NOTE]
>
> Prefer [`useUser`](https://docs.sublay.io/v7/hooks/user/use-user) for typical profile management. `useUserActions` is intended for cases where you need direct control over user state, such as custom authentication integrations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.