Skip to main content

Overview

useFetchUser returns a function that fetches a user’s public profile by their Sublay user ID. Use this when you have the user’s id and need to load their profile on demand.

Usage Example

import { useFetchUser } from "@sublay/react-js";
import { useState } from "react";

function UserCard({ userId }: { userId: string }) {
  const fetchUser = useFetchUser();
  const [user, setUser] = useState(null);

  const load = async () => {
    const result = await fetchUser({ userId });
    setUser(result);
  };

  return <button onClick={load}>Load Profile</button>;
}

Parameters

The hook returns a function. That function accepts:
userId
string
required
The Sublay user ID to fetch.
include
string | string[]
Optional. Pass "files" to populate avatarFile and bannerFile with full File objects.
spaceReputationId
string
Optional. Resolves the returned user’s reputation into a spaceReputation number. Accepts a space <uuid> or "none" (project-general bucket) only — "context" is rejected with a 400 on this endpoint. Empty string, "general", and null are also rejected. See Reputation.
spaceReputationDescendants
boolean
Optional. When true, spaceReputation is the subtree sum (the space plus all its descendants). Only honored when spaceReputationId is an explicit <uuid>.

Returns

User
User
The user’s public profile. When spaceReputationId is set, it carries an added spaceReputation number. See User data model and Reputation.