> For the complete documentation index, see [llms.txt](https://docs.questera.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.questera.ai/questera-ai-sdks/react-native-sdk-components/gamification/leaderboard-component.md).

# Leaderboard Component

## Components Visuals&#x20;

<figure><img src="/files/Ok7A15afsJNrWHh7Qsq6" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="info" %}
To unlock early access to the component                                                           [**Get Access**](https://bijfwfnqtsj.typeform.com/to/eUXDpbuh)
{% endhint %}

## Installation

To install the `Quest react-native-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:

```jsx
npm install @questlabs/react-native-sdk
```

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

{% hint style="info" %}
Make sure your project has npm and Node.js installed, and that you have the necessary permissions to install packages in your project directory.
{% endhint %}

## Usage

### Root Component

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

```jsx
import { QuestProvider } from '@questlabs/react-sdk';
```

* **Pass the Required Props**:  Pass the required props to the `QuestProvider`. The required props are `apiKey`,  `entityId,` `authenticationToken` and `fontFamily.`

{% hint style="info" %}
To load external fonts, please refer this doc to setup [expo-font](https://docs.expo.dev/versions/latest/sdk/font/) on your expo app.
{% endhint %}

### Component Usage

To integrate the `useLeaderboard` component into your React native application, follow these steps.

* **Import useLeaderboard  Hook:** Import the `useLeaderboard` component from the `@questlabs/react-sdk` package.
* **Import the Leaderboard Component**: Import the `Leaderboard` component from the `@questlabs/react-sdk` package.
* **Pass the Required Props**:  Pass the required props to the `useLeaderboard`.  The required props are  `questUserId`, and `userToken` or if user don't have quest User id then they  can pass own `userId` to get questUserId and Token.&#x20;

```typescript
import { useLeaderboard , Leaderboard } from "@questlabs/react-native-sdk";
```

{% hint style="info" %}
Don't not use QuestProvider and useLeaderboard Hook in same file
{% endhint %}

## Props of Leaderboard Component

The Leaderboard component accepts the following props

<table><thead><tr><th width="167">Props Name</th><th width="154">Type</th><th width="103">Require </th><th>Details</th></tr></thead><tbody><tr><td>leadersData</td><td>ITopThree[]</td><td>Require</td><td>in offline user need to provide the require filed data.</td></tr><tr><td>loading</td><td>boolean</td><td>Optional</td><td>don't use in offline mode.</td></tr><tr><td>cardTitle </td><td>string</td><td>Optional</td><td>Title for list.</td></tr><tr><td>cardDescription </td><td>string</td><td>Optional</td><td>Description for list.</td></tr><tr><td>header</td><td>string</td><td>Optional</td><td>Header text for component.</td></tr><tr><td>styleConfig</td><td>object</td><td>Optional</td><td>An object containing Styling properties for styling various components within the get started process, including form, topbar, headings, descriptions,  and buttons.</td></tr></tbody></table>

### Style Props

```typescript
styleConfig {
  Description?: TextStyle;
  Footer?: {
    FooterStyle?: ViewStyle;
    FooterText?: TextStyle;
    FooterIcon?: TextStyle;
  };
  Form?: ViewStyle;
  Heading?: TextStyle;
  IconStyle?: TextStyle;
  IndexBackground?: ViewStyle;
  IndexColor?: TextStyle;
  InnerBackground?: ViewStyle;
  MainHeading?: TextStyle;
  PointsBackground?: ViewStyle;
  PointsColor?: TextStyle;
  ProgressBarColor?: ViewStyle;
}
```

### Example Usage

App.js

```typescript
import { SafeAreaView, StyleSheet, StatusBar } from "react-native";
import React, { useState } from "react";
import { QuestProvider } from "@questlabs/react-native-sdk";
import DemoComponent from "./DemoComponent";

export default function App() {
return (
    <SafeAreaView style={styles.container}>
      <StatusBar />
      <QuestProvider
        apiKey="Your-Api-Key"
        apiSecret="Your-Api-Secret"
        entityId="Your-Api-entityId"
        authenticationToken="Your-authentication-token"  
         fontFamily= "Your-Font-FamFamily"
        >
        
        <DemoComponent />
        
        </QuestProvider>
   
    </SafeAreaView>
  );
}
```

DemoComponent.tsx

```typescript
import React from "react";
import {Leaderboard ,useLeaderboard} from "@questlabs/react-native-sdk";
const DemoComponent = () => {
  // const LeaderboardItem = useLeaderboard({
  //   questId: "Your-Quest_ID" ,
  //   userId:"5235trfet365try67ywry5"
  //   })

  const LeaderboardItem = useLeaderboard({
    questUserId: "Your-user-id",
    questToken: "Your-Token-id" 
    });
  return (
    <>
     <Leaderboard
        leadersData={LeaderboardItem.leadersData}
        loading={LeaderboardItem.loading}
        cardDescription="this is new description"
        cardTitle="This is new title"
        header="My leaderboard"
    /*  styleConfig={{
          Description: { color: "red" },
          Footer: {
            FooterIcon: { color: "red" },
          },
          Form: {
            backgroundColor: "red",
          },
          Heading: { color: "orange" },
          IconStyle: { color: "black" },
          IndexBackground: { backgroundColor: "red" },
          IndexColor: { color: "yellow" },
          InnerBackground: { backgroundColor: "yellow" },
          MainHeading: { color: "yellow" },
          PointsBackground: { backgroundColor: "blue" },
          PointsColor: { color: "yellow" },
          ProgressBarColor: { backgroundColor: "orange" },
        }} */
      />


 {/* <Leaderboard
       
       leadersData={[
        {
          name: "ashish",
          runningXP: 10000,
          userId: "1111",
          imageUrl: "siongpsn",
          xpLimit:50000
        },
        {
          name: "Vishal",
          runningXP: 2000,
          userId: "222",
          imageUrl: "siongpsn",
          xpLimit:5000
        },
        {
          name: "Pankej",
          runningXP: 1000,
          userId: "3333",
          imageUrl: "siongpsn",
            xpLimit:1000
        },
        {
          name: "Rohit",
          runningXP: 500,
          userId: "4444",
          imageUrl: "siongpsn",
            xpLimit:1000
        },
        {
          name: "paras",
          runningXP: 400,
          userId: "555",
          imageUrl: "siongpsn",
            xpLimit:1000
        },
       ]}
      /> */}
    </>
  );
};
export default DemoComponent;
```

## Demo

{% embed url="<https://www.loom.com/share/7872f01d81a64a9682bfdb722b721a89?sid=2ab60c13-68c4-4240-818a-716b5828ed90>" %}
