useUser for PubNub Chat Components for React

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

This hook also sets up a listener that will react 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] = useUser({ uuid: "user" });

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

Input

ParameterTypeRequiredDefaultsDescription
uuidStringOptionalcurrent uuidUnique user identifier. If not supplied, the current user's uuid is used.
includeObjectOptionaln/aOption to include respective additional fields in the response.
 customFieldsBooleanOptionalfalseOption to fetch custom fields.

Output

ParameterTypeDescription
array[0]UserMetadata of the user.
array[1]ErrorIf there's an error fetching the user, it will be available here.
On this page