Badge Component

The Badge component visually represents user achievements, showcasing earned badges within your application.

Component Visuals

To unlock early access to the component Get Access


In this video, you'll learn:

  1. How to set up the QuestProvider with your API credentials.

  2. Configuration of the Badge component with required props.

  3. Integration of the component into your React application.


Installation

To install the Quest react-sdk into your project, follow these steps:

  • Open your terminal/command prompt.

  • Navigate to your project's root directory using the cd command if you're not already there.

  • Run the following command to install the quest-sdk package using npm:

npm install @questlabs/react-sdk

This command will download and install the package and its dependencies into your project.

Make sure your project has npm and Node.js installed, and that you have the necessary permissions to install packages in your project directory.


Props of Badge Component

The Badgecomponent accepts the following props

Prop NameTypeRequiredDetails

userId

string

required

The userId prop is a unique identifier for the user whose badges you want to display. It is required to fetch and display the user's badges.

token

string

required

The token prop is an authentication token or API key that authorizes access to badge data. It is required to fetch badge information for the specified user.


Usage

To integrate the Badgecomponent into your React application, follow these steps

  • Import the CSS: In your JavaScript or TypeScript file where you're using the Badges, import the CSS styles for the component. This ensures that the component's styling is applied correctly.

import '@questlabs/react-sdk/dist/style.css'
  • Import the Badge Component: Import the Badgecomponent from the @questlabs/react-sdk package.

  • Import the QuestProvider Component: Import the QuestProvider component from the @questlabs/react-sdk package.

import { QuestProvider, Badge} from '@questlabs/react-sdk';
  • Pass the Required Props: Pass the required props to the QuestProvider. The required props are apiKey, apiSecret, and entityId. and required props for the Badgecomponent are userId, token

<QuestProvider
  apiKey="your-api-key"
  entityId="your-entity-id"
>
  <Badge
    userId="userId"
    token="your-token"
  />
</QuestProvider>

Replace "your-api-key", "your-api-secret", and "your-entity-id" with your actual Quest API credentials

Replace "userId" and "your-token" with your actual configuration details.


Example Usage

Here's an example of how to use the Badgecomponent within your React application

import { QuestProvider, Badge } from '@questlabs/react-sdk';
import '@questlabs/react-sdk/dist/style.css';

function App() {
  return (
    <div>
      <QuestProvider
        apiKey="k-xxxxxdc-ac8f-x1-xxx8b-a175xxxxx"
        entityId="e-xxxx-b75b-xxxx-be9a-ee11f0f0xxxx"
      >
        <Badge
          userId="u-aebcxxxxx-xxxx-xxxx-xxxx-7c454c1xxxxx"
          token="xxxxxxxxxxxxxxxxcCI6IkpXVCJ9.xxxxxxxxOiJ1LWFlYjM2Njc0LTExNxxxxxxxx"
         />
      </QuestProvider>
    </div>
  );
}

export default App;

The above example uses all the props.



Last updated