Skip to main content

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 badge
  • badgeId - badge ID
  • clientId - ID of the client who owns the badge
  • acquisitionDate - badge receipt date
  • metaInfo - user information
  • name - badge name
  • description - badge description
  • permanent - flag indicating a permanent or temporary badge

Status

  • initial - initial status, the request has not yet been sent
  • done - the request was successful
  • fail - 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} />);
};