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

# Use Fetch Following

# `useFetchFollowing`

## Overview

The `useFetchFollowing` hook fetches the list of users that the current logged-in user is following. It returns paginated results with detailed follow information including when each follow occurred.

## Usage Example

```tsx theme={null}
import { useFetchFollowing } from "@replyke/react-js";

function MyFollowingList() {
  const fetchFollowing = useFetchFollowing();

  const loadFollowing = async () => {
    try {
      const result = await fetchFollowing({ page: 1, limit: 10 });

      console.log(`Following ${result.pagination.totalCount} users`);
      result.following.forEach(follow => {
        console.log(`Following ${follow.user.username} since ${follow.followedAt}`);
      });
    } catch (error) {
      console.error("Failed to fetch following:", error.message);
    }
  };

  return <button onClick={loadFollowing}>Load Who I'm Following</button>;
}
```

## Advanced Usage with Pagination

```tsx theme={null}
import { useFetchFollowing, FollowingResponse } from "@replyke/react-js";
import { useState } from "react";

function PaginatedFollowingList() {
  const fetchFollowing = useFetchFollowing();
  const [following, setFollowing] = useState<FollowingResponse | null>(null);
  const [loading, setLoading] = useState(false);

  const loadPage = async (page: number) => {
    setLoading(true);
    try {
      const result = await fetchFollowing({ page, limit: 15 });
      setFollowing(result);
    } catch (error) {
      console.error("Failed to load following:", error.message);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div>
      {following?.following.map(follow => (
        <div key={follow.followId}>
          {follow.user.username} - Following since: {new Date(follow.followedAt).toLocaleDateString()}
        </div>
      ))}

      {following && (
        <div>
          Page {following.pagination.currentPage} of {following.pagination.totalPages}
          {following.pagination.hasNextPage && (
            <button onClick={() => loadPage(following.pagination.currentPage + 1)}>
              Next Page
            </button>
          )}
        </div>
      )}
    </div>
  );
}
```

## Parameters & Returns

### Parameters

The hook returns a function that accepts an optional object with the following fields:

<ParamField path="page" type="number">
  1
</ParamField>

<ParamField path="limit" type="number">
  20
</ParamField>

### Returns

The function returns a Promise that resolves to a `FollowingResponse` object containing:

#### `FollowingResponse`

<ResponseField name="following" type="FollowingWithFollowInfo[]">
  Array of following information
</ResponseField>

<ResponseField name="pagination" type="PaginationInfo">
  Pagination metadata
</ResponseField>

#### `FollowingWithFollowInfo`

| Field        | Type     | Description                                  |
| ------------ | -------- | -------------------------------------------- |
| `followId`   | `string` | Unique ID of the follow relationship         |
| `user`       | `User`   | User object containing following information |
| `followedAt` | `string` | ISO date string of when the follow occurred  |

#### `PaginationInfo`

| Field             | Type      | Description                                     |
| ----------------- | --------- | ----------------------------------------------- |
| `currentPage`     | `number`  | Current page number                             |
| `totalPages`      | `number`  | Total number of pages available                 |
| `totalCount`      | `number`  | Total number of users you're following          |
| `hasNextPage`     | `boolean` | Whether there are more pages after current page |
| `hasPreviousPage` | `boolean` | Whether there are pages before current page     |
| `limit`           | `number`  | Number of items per page used in this request   |

### Error Handling

The hook will throw errors in the following cases:

* No project is specified
* No user is logged in
