useUpdateUser

Overview

The useUpdateUser hook is used to update a user’s profile details within the current project. This includes updating fields such as name, username, avatar, bio, and more. It also supports metadata updates for flexible user data management.

Usage Example

import { useUpdateUser } from "@replyke/react-js";
 
function UpdateUserForm({ userId }: { userId: string }) {
  const updateUser = useUpdateUser();
 
  const handleUpdateUser = async () => {
    try {
      const updatedUser = await updateUser({
        userId,
        update: {
          name: "John Doe",
          username: "johndoe123",
          bio: "Loving life and coding!",
        },
      });
 
      console.log("User updated successfully:", updatedUser);
    } catch (error) {
      console.error("Failed to update user:", error.message);
    }
  };
 
  return <button onClick={handleUpdateUser}>Update User</button>;
}

Parameters & Returns

Parameters

The hook returns a function that accepts an object with the following fields:

ParameterTypeRequiredDescription
userIdstringYesThe ID of the user to update.
updateUpdateUserParamsYesThe fields and values to update for the user.

UpdateUserParams

FieldTypeRequiredDescription
namestring | nullNoThe new name for the user.
usernamestring | nullNoThe new username for the user.
avatarstring | nullNoThe URL of the user’s avatar.
biostringNoA short biography for the user.
birthdateDate | nullNoThe user’s birthdate.
location{ latitude: number; longitude: number } | nullNoThe user’s geographic location.
metadataRecord<string, any>NoAdditional metadata associated with the user.
secureMetadataRecord<string, any>NoSensitive metadata for the user, not attached to Entity and Comment data.

Returns

The function resolves with an object containing the updated user details:

Return ValueTypeDescription
UserLeanUserLeanThe updated user object.