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
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
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:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
page | number | No | 1 | Page number for pagination |
limit | number | No | 20 | Number of following users to return per page |
Returns
The function returns a Promise that resolves to a FollowingResponse
object containing:
FollowingResponse
Field | Type | Description |
---|---|---|
following | FollowingWithFollowInfo[] | Array of following information |
pagination | PaginationInfo | Pagination metadata |
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