useGMFYBadges
import { useGMFYBadges } from 'gmfy-sdk'
Motivation
If you need to render your UI or simply process data, you can use the useGMFYBadges
hook. The hook allows you to get a list of user badges with userId
. In case updateInterval
was passed in provider component config, it will return new values every updateInterval
ms. Returns a list of badges and the current request status
Typing
type Badge = {
userId:string
badgeId:string;
clientId:string
acquisitionDate: string;
metaInfo: Record<string, any>;
name:string;
description?: string;
permanent: boolean;
}
type Status = 'initial' | | 'done' | 'fail'
useGMFYBadges(): { badges: <Array<Badge>> | null; status: Status }
Badge
userId
- ID of the user who owns the badgebadgeId
- badge IDclientId
- ID of the client who owns the badgeacquisitionDate
- badge receipt datemetaInfo
- user informationname
- badge namedescription
- badge descriptionpermanent
- flag indicating a permanent or temporary badge
Status
initial
- initial status, the request has not yet been sentdone
- the request was successfulfail
- an error occurred while executing the request
Usage
import { useGMFYBadges } from 'gmfy-sdk';
const App = () => {
const { badges, status } = useGMFYBadges();
if (status !== 'done') {
return<Preloader/>;
}
return badges.map((badge) => <YourBadgeComponent key={badge.badgeId} {...badge} />);
};