React & React NativeHooksUsersuseFetchSingleUser

useFetchSingleUser

Overview

The useFetchSingleUser hook is used to retrieve detailed information about a specific user within the current project by their user ID. This can be useful for displaying user profiles or fetching data for interactions.

Usage Example

import { useFetchSingleUser } from "@replyke/react-js";
 
function UserProfile({ userId }: { userId: string }) {
  const fetchSingleUser = useFetchSingleUser();
 
  const handleFetchUser = async () => {
    try {
      const user = await fetchSingleUser({ userId });
      console.log("Fetched user details:", user);
    } catch (error) {
      console.error("Failed to fetch user details:", error.message);
    }
  };
 
  return <button onClick={handleFetchUser}>Fetch User</button>;
}

Parameters & Returns

Parameters

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

ParameterTypeRequiredDescription
userIdstringYesThe ID of the user to fetch.

Returns

The function resolves with a user object containing lean user details:

Return ValueTypeDescription
UserLeanUserLeanThe details of the fetched user object.