The ID of the user to fetch.
The returning object contains:
refresh
: FetchUserMethod - Function to refresh the user data.fetched
: A boolean flag indicating whether the user data has been fetched.user
: The fetched user object or null
if not yet available.useEffect
hook is used to initiate the data fetch when
the userId changes.Example using the useUser
hook within a component with a test user ID to fetch and
display user data.
import { useUser } from 'react-playmakers';
export default function UserComponent() {
// calling with test user ID
const { user } = useUser("50ecc99c-f0d1-7003-0cfe-b0be62e6363f");
// Display the user's username if available
return (
<div>
<h1>Welcome, {user?.username}</h1>
</div>
);
}
Generated using TypeDoc
Custom React hook for fetching and managing user data.