useUser for PubNub Chat Components for React Native

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} />


uuidStringOptionalcurrent User IDUnique user identifier. If not supplied, the current user's User ID is used.
includeObjectOptionaln/aOption to include respective additional fields in the response.
→ customFieldsBooleanOptionalfalseOption to fetch custom fields.


array[0]UserMetadata of the user.
array[1]ErrorIf there's an error fetching the user, it will be available here.
array[2]BooleanIndicator that the user data is still being loaded.
Last updated on
On this page