useFollowManager
Overview
TheuseFollowManager hook is a comprehensive follow state management solution that combines follow status checking, following, and unfollowing functionality into a single, easy-to-use interface. It automatically manages loading states and provides a toggle function for seamless follow/unfollow interactions.
Usage Example
Advanced Usage with Complete UI State
Usage in User Profile Card
Usage with Follow Count Display
Parameters & Returns
Parameters
The hook accepts an object with the following field:The ID of the user to manage follow status for
Returns
The hook returns an object containing:null`
Whether the follow status is being loaded
Function to toggle the follow status
States
isFollowing
null- Follow status is being loaded or user is not logged intrue- Currently following the userfalse- Not following the user
isLoading
true- Initial follow status is being fetchedfalse- Follow status has been loaded
Error Handling
The hook handles errors internally for status fetching, but thetoggleFollow function can throw errors that should be caught by the consuming component.
Common error scenarios:
- Network issues during follow/unfollow operations
- Authentication problems
- User attempting to follow themselves
- Server-side validation errors
Automatic Behavior
The hook automatically:- Fetches initial follow status when the component mounts
- Prevents actions when the user ID matches the current user’s ID
- Manages optimistic UI updates during toggle operations
- Handles loading states for both initial load and toggle operations
Use Cases
This hook is ideal for:- User profile pages with follow/unfollow buttons
- User discovery interfaces
- Social feed user cards
- User search results
- Follow recommendations
- Bulk follow management interfaces
Related Hooks
useFollowUser- Basic follow functionalityuseUnfollowUserByUserId- Basic unfollow functionalityuseFetchFollowStatus- Follow status checking onlyuseConnectionManager- Similar management hook for connections

