useUser for PubNub Chat Components for React Native

Migrate to Chat SDK

PubNub will stop supporting Chat Components on January 1, 2025 but you are welcome to contribute. Learn how to migrate to the Chat SDK here.

The hook returns metadata for a specified User ID, optionally including its custom data object.

User ID / UUID

User ID is also referred to as UUID/uuid in some APIs and server responses but holds the value of the userId parameter you set during initialization.

This hook also sets up a listener that reacts to updates of the fetched user. However, this behavior requires a living subscription to the user getting updated - this should be handled by the components.

This hook can be used in order not to fetch data about all users of the application. Instead, only the current user metadata is passed into the Chat provider and the senderInfo option is enabled on MessageInput. This way the information about the senders is attached directly to the messages.

const [user, error, isLoading] = useUser({ uuid: "user" });

return (
<Chat users={[user]}>
<MessageInput senderInfo={true} />
</Chat>
);

Input

* required
ParameterDefaultsDescription
uuid
Type: String
current User ID
Unique user identifier. If not supplied, the current user's User ID is used.
include
Type: Object
n/a
Option to include respective additional fields in the response.
→ customFields
Type: Boolean
false
Option to fetch custom fields.

Output

ParameterDescription
array[0]
Type: User
Metadata of the user.
array[1]
Type: Error
If there's an error fetching the user, it will be available here.
array[2]
Type: Boolean
Indicator that the user data is still being loaded.
Last updated on
On this page