> ## Documentation Index
> Fetch the complete documentation index at: https://useaward.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# usePoints

The usePoints hook provides a way to get the current user's points and to add points to the current user.

## Usage

### Get Points

<CodeGroup>
  ```jsx points.tsx theme={null}
      import { usePoints } from '@useawards/useaward-expo';
      import { useEffect, useState } from 'react';
      import { Text, View } from 'react-native';

      export default function Points() {
          const { isLoaded, getPoints } = usePoints();
          const [points, setPoints] = useState<number>([]);

          useEffect(() => {
              if (isLoaded) {
              const fetchPoints = async () => {
                  const points = await getPoints();
                  setPoints(points);
              }

              fetchPoints();
              }
          }, [isLoaded, getPoints]);

          return (
              <View>
                  {points ?? 0}
              </View>
          )
      }
  ```

  ```jsx points.js theme={null}
      import { usePoints } from '@useawards/useaward-expo';
      import { useEffect, useState } from 'react';
      import { Text, View } from 'react-native';

      export default function Points() {
          const { isLoaded, getPoints } = usePoints();
          const [points, setPoints] = useState([]);

          useEffect(() => {
              if (isLoaded) {
              const fetchPoints = async () => {
                  const points = await getPoints();
                  setPoints(points);
              }

              fetchPoints();
              }
          }, [isLoaded, getPoints]);

          return (
              <View>
                  {points ?? 0}
              </View>
          )
      }
  ```
</CodeGroup>

### Add Points

<CodeGroup>
  ```jsx points.tsx theme={null}
      import { usePoints } from '@useawards/useaward-expo';
      import { useEffect, useState } from 'react';
      import { TouchableOpacity, Text, View } from 'react-native';

      export default function Points() {
          const { addPoints } = usePoints();

          const handleAddPoints = async () => {
              await addPoints(100, "Some reason"); // reason can be empty or null
          }

          return (
              <View>
                  <TouchableOpacity onPress={handleAddPoints}>
                      <Text>Add Points</Text>
                  </TouchableOpacity>
              </View>
          )
      }
  ```

  ```jsx points.js theme={null}
      import { usePoints } from '@useawards/useaward-expo';
      import { useEffect, useState } from 'react';
      import { TouchableOpacity, Text, View } from 'react-native';

      export default function Points() {
          const { addPoints } = usePoints();

          const handleAddPoints = async () => {
              await addPoints(100, "Some reason"); // reason can be empty or null
          }

          return (
              <View>
                  <TouchableOpacity onPress={handleAddPoints}>
                      <Text>Add Points</Text>
                  </TouchableOpacity>
              </View>
          )
      }
  ```
</CodeGroup>

### Points history

<CodeGroup>
  ```jsx points.tsx theme={null}
      import { usePoints } from '@useawards/useaward-expo';
      import { useEffect, useState } from 'react';
      import { Text, View } from 'react-native';

      export default function PointsHistory() {
          const { isLoaded, getPointsHistory } = usePoints();

          useEffect(() => {
              if (isLoaded) {
                  const fetchHistory = async () => {
                      const history = await getPointsHistory(); // you can pass page number as an argument
                  }

                  fetchHistory();
              }
          }, [isLoaded, getPointsHistory]);

          return (
              <View>
                  ...
              </View>
          )
      }
  ```

  ```jsx points.js theme={null}
      import { usePoints } from '@useawards/useaward-expo';
      import { useEffect, useState } from 'react';
      import { Text, View } from 'react-native';

      export default function PointsHistory() {
          const { isLoaded, getPointsHistory } = usePoints();

          useEffect(() => {
              if (isLoaded) {
                  const fetchHistory = async () => {
                      const history = await getPointsHistory(); // you can pass page number as an argument
                  }

                  fetchHistory();
              }
          }, [isLoaded, getPointsHistory]);

          return (
              <View>
                  ...
              </View>
          )
      }
  ```
</CodeGroup>

History object:

```json theme={null}
{
    "data": [{
        "id": 1,
        "points": 100,
        "reason": "Some reason",
        "createdAt": "2021-01-01T00:00:00.000Z"
    }],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "per_page": 10,
        "to": 7,
        "total": 7
    }
}
```
